Reputation: 1
I am new to vb.net and I am trying to insert a values from vb.net to msacess. I know alredy have a answer for this question here but those answers were not solving my problems so I post again
I am getting an error while inserting data into a database.
Ms-acess :
table name: reg
_________________
field |datatype
__________________
id |autonum
fname |text
lname |text
course|text
fees |number
amount|number
bal |number
The error is:
Number of query values and destination fields are not the same.
Code:
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
Upvotes: 0
Views: 31
Reputation: 55981
Your SQL string must list the field names, probably:
"insert into reg (fname, lname, course, fees, amount, bal) values ('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "'," + TextBox4.Text + "," + TextBox5.Text + "," + TextBox6.Text + ")"
Upvotes: 1