Click here to Skip to main content
15,909,897 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have only one colum in back end database that is roll. ..
Now i want to update a particular data ..
how can i do this
My code is---

VB
dim s1 as integer=TextBox1.Text
  str = "UPDATE  Table1 SET roll=" & TextBox1.Text & "  WHERE roll= " & s1 & " "
        cmd = New SqlCommand(str, cn)
        cmd.ExecuteNonQuery()
Posted

If roll is a string type, I don't think your query will work, unless you place single quotes around the values. In addition, one way to improve your code is to use parameters. See below for example.
VB
str = "UPDATE Table1 SET roll=@rollVal1 WHERE roll=@rollVal2"
cmd = New Sqlommand(str, cn)
cmd.Parameters.AddWithValue("@rollVal1", TextBox1.Text)
cmd.Parameters.AddWithValue("@rollVal2", sl)
cmd.ExecuteNonQuery()


[Edit]
See here[^] for reference.
 
Share this answer
 
v2
Comments
OriginalGriff 31-Jul-11 4:13am    
Much better!
walterhevedeich 31-Jul-11 4:44am    
Thanks.
Neeil 31-Jul-11 4:21am    
no it is not a string,,,it is numbar data type..(integer)
walterhevedeich 31-Jul-11 4:43am    
As far as I know, AddWithValue method converts the data type automatically, so the code I provided should be able to convert the parameters to Int type. You can try that out. Also, see my updated answer for reference.
Try These code, it is working.

dim s1 as integer=TextBox1.Text
str = "UPDATE Table1 SET roll=" & TextBox1.Text & ""
cmd = New SqlCommand(str, cn)
cmd.ExecuteNonQuery()
 
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