preethi_ga 0 Light Poster

Hi ,
In the Insert button i have used the follwing coding,

cmd = New OleDb.OleDbCommand("insert into emp values( ' " & TextBox1.Text & " ' , " & TextBox2.Text & "

Textbox 1 has String and Textbox 2 has Numeric data.

con.Open() 
 cmd.ExecuteNonQuery

Connection string "con" declared Globally.
By executing the code i got error like, "OleDb Exception was UnHandled by the user code"
" Line 1: Incorrect syntax Error "


After that i changed the code,

Dim Ssql as String = "insert into emp(nam,regno)values(@nam,@regno)" 
 cmd = New SqlCommand(Ssql,con) 
 Dim Op1,Op2 as SqlParameter 
 Op1 = cmd.Parameter("@nam",SqlDbType.Char)) 
 Op2 = cmd.Parameter("@regno",SqlDbType.Char)) 
 Op1.Direction = ParameterDirection.Input

Like wise for Op2 also.

Op1.Value = TextBox1.Text 
 Op2.Value = Textbox2.Text 
 cmd.ExecuteNonQuery

So by executing the above code, there is no error but same data's are inserted again and again, like if the textbox1 = preethi, textbox2 = 2001 are the data alredy present. then if i
clear those data by the "ADDNEW button" and if i insert new data , the new data are not stored, again that preethi and 2001 are stored.
i donno what will be the mistake..........!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.