Results 1 to 4 of 4

Thread: why this update statement doesnt work

  1. #1

    Thread Starter
    Frenzied Member maged's Avatar
    Join Date
    Nov 2002
    Location
    Egypt
    Posts
    1,040

    why this update statement doesnt work

    hi all, please check this code vb.net

    VB Code:
    1. Dim contact As Byte = CByte(radioyes.Checked)
    2.         Dim db As New OleDb.OleDbConnection(dbstring), usercode As Long = Request.Cookies("usercode").Value
    3.         'executing several updates
    4.         db.Open()
    5.         Dim cmd As New OleDb.OleDbCommand("update [users] set users.birthdate = #" & txtbirthdate.Text & "# where users.serial = " & usercode.ToString, db)
    6.         Dim xx As Long
    7.         xx = cmd.ExecuteNonQuery()
    8.         Dim cmd2 As New OleDb.OleDbCommand("update [users] set users.mail = '" & txtemail.Text & "' where users.serial = " & usercode.ToString, db)
    9.         cmd2.ExecuteNonQuery()
    10.         Dim cmd3 As New OleDb.OleDbCommand("update [users] set users.contact = " & CByte(radioyes.Checked).ToString & " where users.serial = " & usercode.ToString, db)
    11.         cmd3.ExecuteNonQuery()
    12.         db.Close()
    13.         Response.Redirect("frmview.aspx")


    this is supposed to update a user profile on an asp web page.

    i have checked the usercode variable and it is working fine, but the database is not updated.

    no errors are generated , but the data still the same


    can anyone help me here ?????


    thx in advance

  2. #2
    Member
    Join Date
    May 2001
    Location
    North East Germany
    Posts
    46
    Hi,

    1.
    you are using 3 Updates for only one record?

    Update -table- SET field1 = value1, fieldx = valuex WHERE XY = Z

    2.
    xx = cmd.ExecuteNonQuery()

    Is this truly the correct sub?

    3.
    Maybe you should use ADO, if possible.

    cu
    http://www.fin-sn.de

  3. #3

    Thread Starter
    Frenzied Member maged's Avatar
    Join Date
    Nov 2002
    Location
    Egypt
    Posts
    1,040
    hi Jens_Radtke


    about your points,

    1 - the problem stays still even when i execute one update statement on the row instead of three

    2 - this is not a query, so i think executenonquery is the right solution for (update,insert,delete statements)

    3 - This is actually ADO.Net. so i dont see your point

  4. #4
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    Surround each occurence of "users" with brackets.
    If you're calling ToString on some elements of the SQL, you'd need to surround those with single quotes as well.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width