Error : Table Insertion returns error in vb.net and msacess
Error : Table Insertion returns error in vb.net and msacess
我是 vb.net 的新手,我正在尝试将 vb.net 中的值插入到 msacess。我知道这里已经有了这个问题的答案,但这些答案并没有解决我的问题,所以我再次 post
我在将数据插入数据库时遇到错误。
女士访问:
table name: reg
_________________
field |datatype
__________________
id |autonum
fname |text
lname |text
course|text
fees |number
amount|number
bal |number
错误是:
Number of query values and destination fields are not the same.
代码:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If (TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or TextBox4.Text = "" Or TextBox5.Text = "" Or TextBox6.Text = "") Then
MessageBox.Show("Field Not Empty")
End If
connection = New OleDbConnection(ConfigurationManager.ConnectionStrings("DBConnect").ConnectionString)
connection.Open()
command = New OleDbCommand("insert into reg values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "'," + TextBox4.Text + "," + TextBox5.Text + "," + TextBox6.Text + ")", connection)
command.ExecuteNonQuery()
connection.Close()
MessageBox.Show("Data Added")
End Sub
您的 SQL 字符串必须列出字段名称,可能是:
"insert into reg (fname, lname, course, fees, amount, bal) values ('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "'," + TextBox4.Text + "," + TextBox5.Text + "," + TextBox6.Text + ")"
我是 vb.net 的新手,我正在尝试将 vb.net 中的值插入到 msacess。我知道这里已经有了这个问题的答案,但这些答案并没有解决我的问题,所以我再次 post
我在将数据插入数据库时遇到错误。
女士访问:
table name: reg
_________________
field |datatype
__________________
id |autonum
fname |text
lname |text
course|text
fees |number
amount|number
bal |number
错误是:
Number of query values and destination fields are not the same.
代码:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If (TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or TextBox4.Text = "" Or TextBox5.Text = "" Or TextBox6.Text = "") Then
MessageBox.Show("Field Not Empty")
End If
connection = New OleDbConnection(ConfigurationManager.ConnectionStrings("DBConnect").ConnectionString)
connection.Open()
command = New OleDbCommand("insert into reg values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "'," + TextBox4.Text + "," + TextBox5.Text + "," + TextBox6.Text + ")", connection)
command.ExecuteNonQuery()
connection.Close()
MessageBox.Show("Data Added")
End Sub
您的 SQL 字符串必须列出字段名称,可能是:
"insert into reg (fname, lname, course, fees, amount, bal) values ('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "'," + TextBox4.Text + "," + TextBox5.Text + "," + TextBox6.Text + ")"