我認爲最好的方法是使用OleDBAdapter
類。在繼續此過程之前,您需要先構建數據庫。因爲它需要OleDBAdapter
。如果您還記得,您可以使用DataAdapter的Fill()
方法來讀取數據庫中表的內容並填充本地緩存的DataTable對象。
有3個步驟,節省了ADO.Net數據:
- 獲取的數據與
Fill()
方法
- 寫一段代碼,一個本地緩存的副本(或使用控制),使得更改本地緩存副本
- 將更改保存到底層數據庫與
Update()
方法
下面的代碼,
Using conn As New OleDBConnection("connectionString Here")
Using comm As New OleDBCommand()
With comm
.Connection = conn
.CommandType = CommandType.CommandText
.CommandText = "SELECT * FROM youTableName"
End With
Using adapter As New OleDBDataAdapter(comm)
Dim _dataTable As New DataTable()
adapter.Fill(_dataTable)
'add you records here '
' preferably by using loop '
Dim _dataRow As DataRow
_dataRow = _dataTable.NewRow()
_dataRow("colNameA") = "valueA"
_dataRow("colNameB") = "valueB"
'........ '
_dataTable.Rows.Add(_dataRow)
Dim dt_changes As DataTable
dt_changes = _dataTable.Changes()
If Not IsNothing(dt_changes) Then
Using commBuild As OleDbCommandBuilder(adapter)
Dim rowCount as Integer = adapter.Update(dt_changes)
MsgBox(rowCount & " updated")
End Using
End If
End Using
End Using
End Using
這不是主要在這裏回答? http://stackoverflow.com/q/2025501/78522 –
這就是我已經在做的,閱讀下面的答案評論更多的信息 – user1570048
鏈接iDevlop顯示你是簡單的方法。 –