Data inserting problem

Reply

Join Date: Jun 2008
Posts: 38
Reputation: preethi_ga is an unknown quantity at this point 
Solved Threads: 0
preethi_ga preethi_ga is offline Offline
Light Poster

Data inserting problem

 
0
  #1
Jul 20th, 2008
Hi ,
In the Insert button i have used the follwing coding,

  1. cmd = New OleDb.OleDbCommand("insert into emp values( ' " & TextBox1.Text & " ' , " & TextBox2.Text & "
  2.  
Textbox 1 has String and Textbox 2 has Numeric data.

  1. con.Open()
  2. 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,

  1. Dim Ssql as String = "insert into emp(nam,regno)values(@nam,@regno)"
  2. cmd = New SqlCommand(Ssql,con)
  3. Dim Op1,Op2 as SqlParameter
  4. Op1 = cmd.Parameter("@nam",SqlDbType.Char))
  5. Op2 = cmd.Parameter("@regno",SqlDbType.Char))
  6. Op1.Direction = ParameterDirection.Input
Like wise for Op2 also.
  1. Op1.Value = TextBox1.Text
  2. Op2.Value = Textbox2.Text
  3. 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..........!
Last edited by peter_budo; Jul 20th, 2008 at 11:08 am. Reason: Corecting tags, [code=asp.net]YOUR CODE HERE[/code]
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 561 | Replies: 0
Thread Tools Search this Thread



Tag cloud for ASP.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC