Getting a SQL Update syntax error...really shouldn't be?

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default Re: Getting a SQL Update syntax error...really shouldn't be?

    Try putting [ ] round the password column in the UPDATE statement. I think
    that SQL might be seeing that as a reserved word.

    Hope it helps...


    "Kathy Burke" <kathyburke40@attbi.com> wrote in message
    news:uj8KKbpWDHA.1680@tk2msftngp13.phx.gbl...
    > Hi yet again.
    >
    > I have a very simple Change Password aspx. On postback the page load
    > checks the password control against the database...that works fine...so
    > at lease I know the connection string is working, etc.
    >
    > The btnSave_click event also runs, but error out on the
    > Cmd.ExecuteNonQuery() command. In debug, I can see that the "very
    > simple" SQL state is correct, variables there etc. The database table
    > name and field names are correct. However I get a SQL UPDATE Syntax
    > error in vb.net.
    >
    > Can anyone see something wrong?
    >
    > Kathy
    >
    > CODE***********************
    >
    > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    > System.EventArgs) Handles MyBase.Load
    > 'Put user code to initialize the page here
    >
    > If IsPostBack Then
    >
    > Me.SetFocus(Me.txtPass)
    >
    > 'get password from database
    > Dim varUser As String = txtUser.Text
    > Dim Conn1 As New OleDbConnection()
    > Dim Rdr1 As OleDbDataReader
    > Dim strSQL1 As String = "SELECT Password FROM tblUsers WHERE
    > ([UserName] = '" & varUser & "')"
    > Dim Cmd1 As New OleDbCommand(strSQL1, Conn1)
    > Conn1 = New OleDbConnection(strConn)
    > Cmd1.Connection = Conn1
    > Conn1.Open()
    > Rdr1 = Cmd1.ExecuteReader()
    > If Rdr1.Read() Then
    > dbPass.Text = Rdr1("Password")
    > End If
    > Rdr1.Close()
    > Conn1.Close()
    > Else
    > Me.SetFocus(Me.txtUser)
    >
    > End If
    >
    > End Sub
    >
    > Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As
    > System.EventArgs) Handles btnSave.Click
    >
    > If Page.IsValid Then
    >
    > 'save new password to tblUsers
    > Dim varNewPass As String = txtNewPass1.Text
    > Dim varUser As String = txtUser.Text
    >
    > Dim Conn As OleDbConnection
    > Dim Adapter As OleDbDataAdapter
    > Dim Cmd As OleDbCommand
    > Dim strSQL As String
    >
    > strSQL = "UPDATE tblUsers SET Password='" & varNewPass & "'
    > WHERE UserName= '" & varUser & "'"
    >
    > Conn = New OleDbConnection(strConn)
    > Cmd = New OleDbCommand(strSQL, Conn)
    > Conn.Open()
    > Cmd.ExecuteNonQuery() '******ERROR******
    > Conn.Close()
    >
    > Response.Redirect("MainMenu.aspx")
    >
    > End If
    > End Sub
    >
    > *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    > Don't just participate in USENET...get rewarded for it!

    niceguy Guest

  2. Similar Questions and Discussions

    1. Syntax error in UPDATE statement.
      ok i have an update form that i created it is for the admin of the site to add/edit user account info for memebers to login. the form adds or edits...
    2. Syntax error in UPDATE query
      Thanks in advance for any help... I am trying to update form data to a database from code in the action page code below.. the form is a dual purpose...
    3. Syntax Error Update Statement
      Can someone tell me what's wrong with this code? I need help. Thanks! It is an update page. FIRST PAGE: LOGIN CHECK <!--- Filename: ...
    4. Syntax error in update
      I'm using the update record form wizard in Dreamweaver, and am getting this error when I try to submit changes. <cfparam name='FORM.buildnumber'...
    5. syntax error on update
      ugh, thanx for the help guess there's more than one way this syntax works as well rs("firstname")=blahblah i'm just learning sql so i tend to...
  3. #2

    Default Re: Getting a SQL Update syntax error...really shouldn't be?

    niceguy,

    That was it exactly...can't thank you enough!

    Kathy

    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Kathy Burke Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139