插入时出现vb.net错误 [英] vb.net error in insert into
本文介绍了插入时出现vb.net错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在这里有错误。
插入语法错误请帮助我紧急
I have an error in here.
Insert into syntax error pls help me its urgent
Dim msg As String
msg = MsgBox("Filling Up Complete,Do you want to save It?", vbYesNo)
If msg = vbYes Then
cmdInsert.CommandText = "INSERT INTO login (PersonelName,Position,Username,Password,Repassword,PIN) VALUES (?,?,?,?,?,?)"
cmdInsert.Parameters.AddWithValue("PersonelName", TextBoxX1.Text)
cmdInsert.Parameters.AddWithValue("Position", TextBoxX2.Text)
cmdInsert.Parameters.AddWithValue("Username", TextBoxX3.Text)
cmdInsert.Parameters.AddWithValue("Password", TextBoxX4.Text)
cmdInsert.Parameters.AddWithValue("Repassword", TextBoxX5.Text)
cmdInsert.Parameters.AddWithValue("PIN", TextBoxX6.Text)
MsgBox("Registration Complete")
cmdInsert.CommandType = CommandType.Text
cmdInsert.Connection = cnnOLEDB
cmdInsert.ExecuteNonQuery()
TextBoxX1.Text = ""
TextBoxX2.Text = ""
TextBoxX3.Text = ""
TextBoxX4.Text = ""
TextBoxX5.Text = ""
TextBoxX6.Text = ""
Else
End If
推荐答案
cmdInsert.CommandText = "INSERT INTO login (PersonelName,Position,Username,Password,Repassword,PIN) VALUES (@PersonelName,@Position,@Username,@Password,@Repassword,@PIN)"
cmdInsert.Parameters.AddWithValue("@PersonelName", TextBoxX1.Text)
cmdInsert.Parameters.AddWithValue("@Position", TextBoxX2.Text)
cmdInsert.Parameters.AddWithValue("@Username", TextBoxX3.Text)
cmdInsert.Parameters.AddWithValue("@Password", TextBoxX4.Text)
cmdInsert.Parameters.AddWithValue("@Repassword", TextBoxX5.Text)
cmdInsert.Parameters.AddWithValue("@PIN", TextBoxX6.Text)
?是参数的实际名称,而不是列名。你需要告诉参数去哪里,因为命令对数据库的模式一无所知。
The ?'s are the actual names of the parameters, not the column names. You need to tell the parameters where they go, since the command doesn't know anything about the schema of your database.
这篇关于插入时出现vb.net错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文