0

我正在做一个小项目,我必须使用访问数据库。我对“INSERT INTO”语句有一个很大的问题,并且在花了很多时间寻找解决方案之后再次出现。这是代码的一部分:

     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    Try
        connexion.Open()
        Dim cmdString_update As String = "INSERT INTO notes (nom, note) VALUES (@nom, @note)"    
        Dim SQLCommand3 As New OleDbCommand(cmdString_update, connexion)
        SQLCommand3.Parameters.AddWithValue("@nom", nom)
        SQLCommand3.Parameters.AddWithValue("@note", note)
        'SQLCommand3.Parameters.AddWithValue("@commentaire", commentaire)
        SQLCommand3.ExecuteNonQuery()

    Catch ex As OleDbException
        ' Display error
        MsgBox("Error: " & ex.ToString())
    Finally
        ' Close Connection
        connexion.Close()
        MsgBox("Connection Closed")
    End Try

End Sub

这是错误的屏幕截图:h ttps://docs.google.com/file/d/0B3v4Tp1x6sfDMWFEQTJUbUVTTUE/edit?usp=sharing

你能帮我吗 ?这让我非常非常疯狂!

非常感谢,对不起我的英语不好。

(我正在使用 Visual Studio Express 2012 在 VB.NET 中编程。)

4

1 回答 1

1

单词 NOTE 是 MS-Access 中的保留关键字
要在 OleDb 中使用该词,您应该以这种方式更改您的查询...

 Dim cmdString_update = "INSERT INTO notes (nom, [note]) VALUES (@nom, @note)"    

在涉案字段周围添加方括号可以防止误解。
但是,如果仍然可能,请尝试将字段名称更改为其他名称。
否则每次尝试使用该字段时都会遇到此问题。

于 2013-10-22T19:56:27.277 回答