Professional Web Applications Themes

Getting a SQL Update syntax error...really shouldn't be? - ASP.NET General

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" <kathyburke40attbi.com> wrote in message news:uj8KKbpWDHA.1680tk2msftngp13.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 ...

  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" <kathyburke40attbi.com> wrote in message
    news:uj8KKbpWDHA.1680tk2msftngp13.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. #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

Similar Threads

  1. Syntax error in UPDATE query
    By trey2233 in forum Coldfusion Database Access
    Replies: 9
    Last Post: July 1st, 01:20 PM
  2. Syntax Error Update Statement
    By Heather939 in forum Macromedia ColdFusion
    Replies: 1
    Last Post: May 13th, 03:10 AM
  3. Syntax error in update
    By benkayuk in forum Macromedia ColdFusion
    Replies: 16
    Last Post: April 22nd, 07:53 PM
  4. Syntax Error In Update Statement
    By MDW in forum ASP Database
    Replies: 10
    Last Post: October 13th, 10:07 PM
  5. syntax error on update
    By bbxrider in forum ASP Database
    Replies: 0
    Last Post: July 22nd, 08:51 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not 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