从datagridview向MS访问插入数据

时间:2014-05-10 17:14:41

标签: datagridview

helo,我的编码问题,它在INSERT INTO语句中显示语法错误。任何人都可以帮助我..

    Dim con As New OleDb.OleDbConnection

    Dim item As String
    Dim qty As String
    Dim price As String

    For x As Integer = 0 To Me.DataGridView1.Rows.Count - 1
        item = Me.DataGridView1.Rows(x).Cells(0).ToString
        qty = Me.DataGridView1.Rows(x).Cells(1).ToString
        price = Me.DataGridView1.Rows(x).Cells(2).ToString
        con.open()
        Dim da As New OleDbDataAdapter("select * from Customer", con)
        Dim str As String = "INSERT INTO Order(IDNumber, CodeDrink, Price, Quantity) VALUES(@IDNumber, @CodeDrink, @Price, @Quantity)"
        Dim cmd As New OleDb.OleDbCommand(str, con)
        cmd.Parameters.AddWithValue("@IDNumber", MainFrame.TextBox_Id.Text)
        cmd.Parameters.AddWithValue("@CodeDrink", item)
        cmd.Parameters.AddWithValue("@Price", price)
        cmd.Parameters.AddWithValue("@Quantity", qty)
        cmd.ExecuteNonQuery()
        cmd.Dispose()

    Next
    con.Close()

1 个答案:

答案 0 :(得分:0)

将方括号括起来。

insert into [order](....

这是一个保留字。