oledb "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

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

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

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

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

NOTE 一词是 MS-Access 中的保留关键字。
要将这个词与 OleDB 一起使用,您应该以这种方式更改查询......

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

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

相关内容

最新更新