0

DataGridView在对被叫进行更改后,我需要更新我的 Access 数据库DataGridView_Manage_Calculations,然后单击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
4

1 回答 1

1

查看您有关错误消息的信息,您的 SELECT 查询似乎没有在 select 语句中返回表的主键。在这种情况下,OleDbCommandBuilder 不会构建所需的 INSERT 命令。

你有两个选择:

  • 返回所选表的主键
  • 为适配器创建自己的 INSERT/UPDATE/DELETE 命令

我不知道您的表的结构(考虑到动态构造的选择),但最好的方法是在选择语句中返回主键

于 2013-10-11T19:55:11.967 回答