Dim conn2 As New data.Oledb.OleDbConnection(Connections("xls").ConnectionString)
conn2.open()
Dim da As New data.Oledb.OleDbDataAdapter("Select * From [Page1$] Where id < 20", conn2)
Dim ds As Data.DataSet = New Data.DataSet()
ds.datasetname="custdataset"
da.Fill(ds, "MyTable")
Dim tbl As data.DataTabletbl = ds.Tables("MyTable")
Tables(e.Form.Controls("Table1").Table.Name).DataSource = tbl
Tables(e.Form.Controls("Table1").Table.Name).AllowEdit = True
' Generate the UpdateCommand and add the parameters for the command.
da.UpdateCommand = New Data.Oledb.OleDbCommand( _
"UPDATE [Page1$] SET empno = ? WHERE [_Identify] = ?", conn2)
da.UpdateCommand.Parameters.Add("@empno", data.oledb.OleDbType.VarChar,255).SourceColumn = "empno"
da.UpdateCommand.Parameters.Add("@_Identify", Data.Oledb.OleDbType.VarChar,255, "_Identify")
' Update the first two records.
ds.Tables(0).Rows(1)("empno") = "A1330093B"
ds.Tables(0).Rows(2)("empno") = "A1330094"
ds.Tables(0).Rows(3)("empno") = "A1330096"
ds.Tables(0).Rows(4)("empno") = "A1330096"
ds.Tables(0).Rows(5)("empno") = "A1330097A"
ds.Tables(0).Rows(6)("empno") = "A1330098A"
Tables(e.Form.Controls("Table1").Table.Name).Rows(7)("empno")="A1330099A"
' Apply the dataset changes to the actual data source (the workbook).
da.Update(ds, e.Form.Controls("Table1").Table.Name)
conn2.Close()
MessageBox.Show("ok")
狐爸,帮我分析一 下,为什么以上的代码不会更新到指定的表中,UpdateCommand已指定了,那里出错了呀~谢谢