這裏是我的代碼:我與INSERT錯誤INTO語句
Imports System.Data
Imports System.Data.OleDb
Public Class frmAdd
Dim con As New OleDbConnection
Dim com As New OleDbCommand
Dim ins As New OleDbCommand
Dim upd As New OleDbCommand
Dim strcon = ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source = Supplies.mdb")
Private Sub frmAdd_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
con.ConnectionString = strcon
con.Open()
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
ins.CommandText = "INSERT INTO [product info] ([Product Name:],[Description:],[Quantity:],[Type:],[Date Received:],[Barcode:],[Price:]) VALUES ('" & txtItemName.Text & "', '" & txtDescription.Text & "', " & txtItemCount.Text & ", '" & cmbItemType.Text & "', " & txtDate.Text & ", '" & txtBarcode.Text & "', '" & txtPrice.Text & "',);"
ins.Parameters.AddWithValue("@name", txtItemName.Text)
ins.Parameters.AddWithValue("@desc", txtDescription.Text)
ins.Parameters.AddWithValue("@count", Convert.ToInt32(txtItemCount.Text))
ins.Parameters.AddWithValue("@type", cmbItemType.Text)
ins.Parameters.AddWithValue("@dt", Convert.ToDateTime(txtDate.Text))
ins.Parameters.AddWithValue("@code", txtBarcode.Text)
ins.Parameters.AddWithValue("@price", txtPrice.Text)
ins.CommandType = CommandType.Text
ins.Connection = con
ins.ExecuteNonQuery()
ins.Dispose()
con.Close()
我填寫了所有的文本框後,我打的保存按鈕,當我打的保存按鈕錯誤「語法錯誤INSERT INTO語句。「
列名中的冒號是故意的。我在問題中編輯了我的查詢,請檢查是否還有錯誤。謝謝 –
不,還有錯誤:''[條形碼:,價格:]'應該是'[Barcode:],[Price:]',並且從VALUES(.....)中刪除你的文字,然後使用?佔位符 – Steve
我剛剛修復它,但插入語句仍存在錯誤 –