OleDb 错误 Visual Basic 中的未知字段名称“名称”



嘿,有很多这样的问题,但我没有找到正确的问题。 我一直收到此错误,

图像

我正在使用vb.net 和 Ms-access 数据库。

我已经研究了,但没有得到任何东西,我检查了名称"productID",它是正确的。所以我不知道怎么了?请帮忙

我的代码:

Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
    Dim dbProvider As String
    Dim dbSource As String
    Dim MyDocumentsFolder As String
    Dim TheDatabase As String
    Dim FullDatabasePath As String
    Dim Sql As String
    Dim con As New OleDb.OleDbConnection
    Dim empty = Me.Controls.OfType(Of TextBox)().Where(Function(txt) txt.Text.Length = 0)
    If empty.Any Then
        MessageBox.Show("Please fill all informations")
    Else
        dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
        TheDatabase = "C:UsersjacobDesktopMS Officeproject.mdb"
        MyDocumentsFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
        FullDatabasePath = MyDocumentsFolder & TheDatabase
        dbSource = "Data Source = " & TheDatabase
        con.ConnectionString = dbProvider & dbSource
        Sql = "INSERT INTO tblUsers (productID, quantity, price, productSection, supplierID) VALUES (@ProductID, @Quantity, @Price, @ProductSection, @SupplierID)"
        MessageBox.Show("Database is now open")
        con.Open()
        Dim command As New OleDb.OleDbCommand(Sql, con)
        command.Parameters.Add("@ProductID", OleDb.OleDbType.VarChar).Value = txtProductName.Text
        command.Parameters.Add("@Quantity", OleDb.OleDbType.Integer).Value = txtQuantity.Text
        command.Parameters.Add("@Price", OleDb.OleDbType.Currency).Value = txtPrice.Text
        command.Parameters.Add("@ProductSection", OleDb.OleDbType.VarChar).Value = txtSection.Text
        command.Parameters.Add("@SupplierID", OleDb.OleDbType.VarChar).Value = txtSupplier.Text
        command.ExecuteNonQuery()
        MessageBox.Show("Product Added Successfully")
        con.Close()
        MessageBox.Show("Database is now Closed")
    End If
End Sub

错误显示在此行中: command.ExecuteNonQuery()

SQL

区分大小写,请检查 Sql 变量中是否有大写的内容,而在 SQL Server 的表中是否大写,反之亦然。

您还可以检查参数的大小写是否也可能导致问题。

相关内容

最新更新