我需要在更改DataGridView
DataGridView_Manage_Calculations
之后更新我的Access数据库,然后点击Button
Button_Update
。
这是我到目前为止的代码:
Dim dtManage As New DataTable
Dim ManageAdapter As OleDbDataAdapter
Dim Bsource As New BindingSource
Public Sub Show_Panel_Manage_Calculations()
Panel_Manage_Calculations.Show()
ManageAdapter = New OleDbDataAdapter("Select Calculation, [Interval], Formula From " & tblName & "", con)
dtManage.Clear()
ManageAdapter.Fill(dtManage)
Bsource.DataSource = dtManage
DataGridView_Manage_Calculations.DataSource = Bsource
End Sub
Private Sub Button_Update_Click(sender As Object, e As EventArgs) Handles Button_Update.Click
Dim ObjComander As New OleDbCommandBuilder(ManageAdapter)
ManageAdapter.Update(dtManage)
End Sub
我收到此错误:Syntax error in INSERT INTO statement.
我做错了什么?
其他信息
Public Sub createTable_Criteria()
Dim cmd As New OleDb.OleDbCommand("CREATE TABLE " & tblName & "(" & "Calculation Text(10) NOT NULL," & "[Interval] Text NOT NULL," & "Formula Text," & "Tier_Juncture_1 Integer," & "Tier_Juncture_2 Integer," & "Tier_Juncture_3 Integer," & "Weight Integer, CONSTRAINT pk_Calculation PRIMARY KEY (Calculation, [Interval]));", con)
cmd.ExecuteNonQuery()
End Sub
答案 0 :(得分:1)
查看有关错误消息的信息,您的SELECT查询似乎不会在select语句中返回表的主键。在这种情况下,OleDbCommandBuilder不会构建所需的INSERT命令。
您有两种选择:
我不知道你的表的结构(给定dinamically构造的select)但最好的方法是在select语句中返回主键