急,OLEAdapter.update
Public Function FG_TrueDBSelect(ByVal strSQL As String) As Data.DataTable
Dim ds As New DataSet
conn.Open()
adapter.SelectCommand = New OleDbCommand(strSQL, conn)
System.Threading.Thread.Sleep(500)
adapter.FillSchema(ds, SchemaType.Source, "table1")
adapter.Fill(ds, "table1")
'如果把更新的操作放在这里,是可以的
Dim oCommandBuilder As New OleDbCommandBuilder(adapter)
ds.Tables("table1").Rows(1)("check") = -1
adapter.DeleteCommand = oCommandBuilder.GetDeleteCommand
adapter.InsertCommand = oCommandBuilder.GetInsertCommand
adapter.UpdateCommand = oCommandBuilder.GetUpdateCommand
'Apply the updates
adapter.Update(ds, "table1")
conn.Close()
Return ds.Tables("table1")
End Function
如果单独提炼出来,做个函数,那么更新,就不可以了
不知道为什么
Public Sub FG_TrueDBUpdate(ByRef dt As DataTable)
Try
conn.Open()
Dim oCommandBuilder As New OleDbCommandBuilder(adapter)
dt.Rows(1)("check") = -1
adapter.DeleteCommand = oCommandBuilder.GetDeleteCommand
adapter.InsertCommand = oCommandBuilder.GetInsertCommand
adapter.UpdateCommand = oCommandBuilder.GetUpdateCommand
'Apply the updates
adapter.Update(dt)
'adapter.Update(ds.Tables("table1"))
conn.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub