如何在刚创建的 DataTable 中使用 DataRow 更新 Access table?
How can I update an Access table with a DataRow in a DataTable I just created?
sSql = "SELECT * FROM tblTicketChanges"
Dim dtChg As DataTable = CreateDataTable(sSql, con)
我在下面的代码中创建了行,然后将其添加到上面创建的名为 dtChg 的数据table。
Public Sub ADOSave2ChangeList(ByRef dt As DataTable, ByRef sFld As String, ByRef sNewValu As String, ByRef sOldValu As String, ByRef sTicketNo As String, ByRef sQualifier As String, ByRef sUser As String, ByRef dDate As Date, ByRef varTime As Date)
Dim r As DataRow = dt.NewRow ' Add new change record
r("ChangeTime") = String.Format("{0:MM/dd/yyyy} {1:hh:mm:ss}", dDate, varTime) ' Change date and time
r("Division") = gDiv ' Division number
r("Location") = gLocation ' Location id
r("TicketNo") = sTicketNo ' Ticket number
r("Qualifier") = NoNull(sQualifier) ' Qualifier
r("FieldName") = sFld ' Name of field that changed
r("OriginalValue") = sOldValu ' Original value
r("NewValue") = sNewValu ' New value
r("ChangedByUser") = sUser ' User id
Debug.WriteLine(String.Join(" ", r.ItemArray))
dt.Rows.Add(r) ' Save changes
gChanged = True ' Flag that change happened
End Sub
有没有一种方法可以在没有 sql 插入语句的情况下使用数据 table dtChg 更新或插入 Access table?或者不使用 sql 语句将新行添加到 Access table 的方法?
我使用 OleDbCommandBUilder 让它工作:
Dim Builder As OleDbCommandBuilder = New OleDbCommandBuilder(da2)
Builder.GetUpdateCommand()
da2.UpdateCommand = Builder.GetUpdateCommand()
da2.Update(ds, "Changes")
我要补充一点,我必须对 DataSet 进行维度标注,并且还将 DataTable 命名为“Changes”。
我不太确定 CommandBUilder 发生了什么,但它看起来非常强大。打算继续阅读。
sSql = "SELECT * FROM tblTicketChanges"
Dim dtChg As DataTable = CreateDataTable(sSql, con)
我在下面的代码中创建了行,然后将其添加到上面创建的名为 dtChg 的数据table。
Public Sub ADOSave2ChangeList(ByRef dt As DataTable, ByRef sFld As String, ByRef sNewValu As String, ByRef sOldValu As String, ByRef sTicketNo As String, ByRef sQualifier As String, ByRef sUser As String, ByRef dDate As Date, ByRef varTime As Date)
Dim r As DataRow = dt.NewRow ' Add new change record
r("ChangeTime") = String.Format("{0:MM/dd/yyyy} {1:hh:mm:ss}", dDate, varTime) ' Change date and time
r("Division") = gDiv ' Division number
r("Location") = gLocation ' Location id
r("TicketNo") = sTicketNo ' Ticket number
r("Qualifier") = NoNull(sQualifier) ' Qualifier
r("FieldName") = sFld ' Name of field that changed
r("OriginalValue") = sOldValu ' Original value
r("NewValue") = sNewValu ' New value
r("ChangedByUser") = sUser ' User id
Debug.WriteLine(String.Join(" ", r.ItemArray))
dt.Rows.Add(r) ' Save changes
gChanged = True ' Flag that change happened
End Sub
有没有一种方法可以在没有 sql 插入语句的情况下使用数据 table dtChg 更新或插入 Access table?或者不使用 sql 语句将新行添加到 Access table 的方法?
我使用 OleDbCommandBUilder 让它工作:
Dim Builder As OleDbCommandBuilder = New OleDbCommandBuilder(da2)
Builder.GetUpdateCommand()
da2.UpdateCommand = Builder.GetUpdateCommand()
da2.Update(ds, "Changes")
我要补充一点,我必须对 DataSet 进行维度标注,并且还将 DataTable 命名为“Changes”。 我不太确定 CommandBUilder 发生了什么,但它看起来非常强大。打算继续阅读。