#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2015
    Location
    Birmingham
    Posts
    1
    Rep Power
    0

    help with SQL update


    Hi, I have just started to learn SQL
    I am stuck on the UPDATE,
    I am using VB.NET on a windows form with Visual Studio 2013. I have created a TextBox and a button on a form, I want it so that when I enter a number in to the TextBox and press the button my SQL database will be updated.
    I have tested my connection string and I know it works. So I believe the problem is my lack of practice with SQL. Anyway


    Table name is "Users"
    Column name is "UserScore"
    Name of textbox I am entering data in to is "UserScore"

    Dim ds As New DataSet
    Dim sql As String
    Dim da As New SqlDataAdapter

    Code:
    sql = "UPDATE Users(UserScore)Values('" & UserScore.Text & "')"
            da = New SqlDataAdapter(sql, con)
            da.Update(ds, "Users")
            MsgBox("Data updated")

    Can someone tell me where I have gone wrong. I do not get any error messages my programme runs without error I even see the message box come up. So my code is being read al the way.
    Thanks for reading.
  2. #2
  3. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,795
    Rep Power
    4332
    Originally Posted by Nige
    I do not get any error messages
    always test your query directly in the database, i.e. not via your VB program

    you have bad sql syntax, you need to fix that first

    also, you will probably want a WHERE condition
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    123
    Rep Power
    14
    your sql
    sql = "UPDATE Users(UserScore)Values('" & UserScore.Text & "')"
    not looks right...
    the syntax for update
    update tableName
    set fiels = value
    where condition

IMN logo majestic logo threadwatch logo seochat tools logo