Click here to Skip to main content
15,883,883 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am using visual studio 2008 nd ms access...i am getting the error in my insert command i have modified the database table also but still i am getting the same error.plz help me..
Private Sub btninsert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btninsert.Click
con.Open()
cmd = New OleDbCommand("insert into b1 values( " & TextBox1.Text & " , ' " & TextBox2.Text & " ' , ' " & TextBox3.Text & " ' , ' " & TextBox4.Text & " ' , " & TextBox5.Text & " , ' " & TextBox6.Text & " ' , " & TextBox7.Text & " , " & TextBox8.Text & " , ' " & TextBox9.Text & " ' , " & TextBox10.Text & " , " & TextBox11.Text & " , ' " & TextBox12.Text & " ' , " & TextBox13.Text & " , " & TextBox14.Text & " , " & TextBox15.Text & " , " & TextBox16.Text & " , " & TextBox17.Text & " )", con)
cmd.ExecuteNonQuery()
MsgBox("INSERTED")
con.Close()
Posted

1 solution

Your approach is wrong from the very beginning. You should never create a query by concatenation of string taken from your UI. Instead, you need to use parametrized statements. Please see: http://msdn.microsoft.com/en-us/library/ff648339.aspx[^].

If you do it your way, you make your application totally vulnerable to a well-known exploit: SQL Injection. The user can write anything in the UI, including some SQL fragment. Are you getting the idea? This is how: http://xkcd.com/327[^].

Please see my past answers:
EROR IN UPATE in com.ExecuteNonQuery();[^],
hi name is not displaying in name?[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900