VB.NET TextBox holds value of the data I want button to update an MS SQL database on...

  • Thread starter Thread starter nigelsvision
  • Start date Start date
N

nigelsvision

Guest
Hi, I am playing around with SQl I have just figured out how to extract the data I want from my MS SQL database on my GoDaddy server. But I cant seem to get it right on how I can update certain things in my database.

I believe there can be nothing wrong with my connection string as I can extract data from my database. So here goes.

I have got a table called Users

A column called UserScore

A column called UserName



I have got a TextBox called UserScore.Text on a windows form



In a button click I have got this

Dim con As New SqlConnection
Dim ds As New DataSet
Dim da As New SqlDataAdapter
Dim sql As String
Dim cmd As SqlCommand = New SqlCommand
Dim dr As SqlDataReader

cmd = New SqlCommand("UPDATE Users(UserScore)Values(" & UserScore.Text & ")Where name=Nige", con)
If con.State = ConnectionState.Closed Then
con.Open()
cmd.ExecuteNonQuery()
da = New SqlDataAdapter(sql, con)
da.Update(ds, "Users")
MsgBox("Data updated")


It crashes on the below line



cmd.ExecuteNonQuery()


with this error
An unhandled exception of type System.Data.SqlClient.SqlException occurred in System.Data.dll

Additional information: Incorrect syntax near (.

What I wanted was when I enter text in to the textbox and press the button it will update my table in the column UserScore for the user called Nige

Thanks for reading

Nige























































Continue reading...
 
Back
Top