Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
VB
Dim cmdupdate As OleDbCommand = New OleDbCommand
      con.Open()
      sql = "UPDATE Info SET [add] = '" & txtadd.Text & "'," _
     & "[phno] = '" & txtphno.Text & "'," _
     & "[emailid] = '" & txtemailid.Text & "'," _
      & "[gender] = '" & txtgender.Text & "'," _
      & "[dob] = '" & txtdob.Text & "'," _
     & "[quali] = '" & txtqual.Text & "'," _
    & "[designation] = '" & txtdegn.Text & "', " _
    & "[salary] = '" & txtsal.Text & "' ," _
    & "[bank] = '" & txtbank.Text & "'" _
    & "WHERE name = " & cmbname.Text & ""

      cmd = New OleDbCommand(sql, con)
      cmd.ExecuteNonQuery()
      con.Close()
      MsgBox(cmbname.Text = "Record updated.")
Posted

Your code is hardly readable, but the problem is just the SQL syntax. Perhaps you will see it and will be able to correct the query if you totally change the approach. You really, really need to use parametrized queries, and by a number of much more important reasons.

Start with:
http://msdn.microsoft.com/en-us/library/ms254953.aspx[^],
http://msdn.microsoft.com/en-us/library/yy6y35y8%28v=VS.100%29.aspx[^] (some OleDb code samples here).

By the way, multiple string concatenation is really bad idea. This is because strings are immutable, so it's bad for performance. Do I even have to explain why? Using string.Format is free from this problem and also much more readable. In other cases (such as cycles), use (mutable) System.Text.StringBuilder.

See:
http://msdn.microsoft.com/en-us/library/system.string.aspx[^],
http://msdn.microsoft.com/en-us/library/system.text.stringbuilder.aspx[^].

—SA
 
Share this answer
 
v2
Comments
thatraja 10-Dec-11 0:33am    
Wise, 5!
Sergey Alexandrovich Kryukov 10-Dec-11 1:14am    
Thank you, Raja.
--SA
Agree with SA. Use parametrized queries. And here I point out some of your mistakes. Also suggestion(s)
VB
sql = "UPDATE Info SET [add] = '" & txtadd.Text & "'," _
     & "[phno] = '" & txtphno.Text & "'," _
     & "[emailid] = '" & txtemailid.Text & "'," _
      & "[gender] = '" & txtgender.Text & "'," _
      & "[dob] = '" & txtdob.Text & "'," _
     & "[quali] = '" & txtqual.Text & "'," _
    & "[designation] = '" & txtdegn.Text & "', " _
    & "[salary] = '" & txtsal.Text & "' ," _
    & "[bank] = '" & txtbank.Text & "'" _
    & "WHERE name = " & cmbname.Text & ""


Put square brackets for the field names.
Here in your code, name field is string type so you should have included the single quotes(WHERE name = '" & cmbname.Text & "'"). And give a space before the WHERE keyword.
 
Share this answer
 
Comments
Manoj K Bhoir 10-Dec-11 2:05am    
My 5!

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