你好我有一個數據庫,我加載到vb.net應用程序Datagridview。 它加載正常,但是當我嘗試保存日期不起作用。 這裏是代碼當新行傳遞的DataRow集合Datagridview保存更改爲數據庫vb.net
Private myConString As String
Private con As OleDbConnection = New OleDbConnection
Private Dadapter As OleDbDataAdapter
Private DSet As DataSet
Private DSet2 As DataSet
Private ConCMD As OleDb.OleDbCommand
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
myConString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=e:\Database31.accdb"
con.ConnectionString = myConString
con.Open()
Dadapter = New OleDbDataAdapter("select * from Table1", con)
DSet = New DataSet
Dadapter.Fill(DSet, "Table1")
DataGridView1.DataSource = DSet.Tables("Table1")
con.Close()
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
con.Open()
Dadapter.Update(DSet, "Table1")
DSet.AcceptChanges()
con.Close()
End Sub
更新需要有效的InsertCommand。 我該怎麼辦?
的accessdatabase 3個colmuns ID是主鍵 ID字段1字段2
謝謝,但仍然是什麼插入命令?!我的數據庫只有3個字段ID Field1 Field2..so我的插入命令應該如何? – FPGA 2012-07-08 00:10:01
編輯我的答案,爲[OleDbDataAdapter.InsertCommand]提供msdn鏈接(http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbdataadapter.insertcommand%28v=vs.100%29。 ASPX)。有一個sql INSERT語句的例子。 – 2012-07-08 00:13:48
偉大..現在假設我填充了數據網格視圖2000個新的值與不同領域的循環..我想保存這是什麼是最好的方法來做到這一點?插入應該在循環期間而不是在循環之後? – FPGA 2012-07-08 00:26:09