Datagridview连接access的更新数据库问题
小弟我又遇上麻烦啦。。还是Datagridview。。
可以实现从 Access DB里面retrieve data
但是update有问题。说是语句有问题。。
An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll
Additional information: UPDATE 语句的语法错误。
什么问题呢?
Imports System.Data.OleDbPublic Class Form1 Dim con As OleDbConnection Dim cmd As OleDbCommand Dim myDA As OleDbDataAdapter Dim myDataSet As DataSet Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim con As OleDbConnection = New OleDbConnection("Provider=Microsoft.jet.oledb.4.0;data source=|DataDirectory|\Database2.mdb") Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM TimePicker", con) con.Open() myDA = New OleDbDataAdapter(cmd) 'One CommandBuilder object is required. It automatically generates DeleteCommand,UpdateCommand and InsertCommand for DataAdapter object Dim builder As OleDbCommandBuilder = New OleDbCommandBuilder(myDA) myDataSet = New DataSet() myDA.Fill(myDataSet, "MyTable") DataGridView1.DataSource = myDataSet.Tables("MyTable").DefaultView con.Close() con = Nothing End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Me.Validate() Me.myDA.Update(Me.myDataSet.Tables("MyTable")) Me.myDataSet.AcceptChanges() End SubEnd Class