iNET Interactive - Online Advertising Agency
          
Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Database and Reporting > SQL UPDATE query problem


Reply
 
Thread Tools Display Modes
  #1  
Old 05-28-2002, 08:02 AM
intersimi
 
Posts: n/a
Question SQL UPDATE query problem

Can any one tell me what is wrong with the statement below. If I cut and paste the SQL into query analyser the update statement works fine.

Code:
If reply2 = vbOK Then
                sql = "update username_table set password = '" & NewPassword _
                    & "' where servername = '" & SelectedServerName _
                    & "' and username = '" & selectedusername & "'"
                rs.Open sql, dbs, adOpenDynamic, adLockReadOnly
                rs.Close
            End If
Reply With Quote
  #2  
Old 05-28-2002, 08:06 AM
intersimi
 
Posts: n/a
Default

Here is the more complete code

Code:
Private Sub Command2_Click()

    Dim dbs As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    Dim strConn As String
    Dim strPath As String
    Dim ReturnedCustomerName As String
    Dim ReturnedPassword As String
    Dim ReturnedUserName As String
    Dim sql As String
    Dim WrapCharacter$
    Dim NewPassword As String
        
    NewPassword = Text1.Text
    WrapCharacter$ = Chr(13) + Chr(10)
       
    strPath = "C:\"
    strConn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & strPath & "\password.mdb"
    dbs.Open strConn
 
    If DataCombo1.BoundText = "" Then
        prompt$ = "You have to select a servername from the drop down list to proceed"
        reply = MsgBox(prompt$, , "Confirm Selection")
            If reply = vbOK Then Exit Sub
    End If

    If Combo1.Text = "" Then
        prompt$ = "You have to select a username from the drop down list to proceed"
        reply = MsgBox(prompt$, , "Confirm Selection")
            If reply = vbOK Then Exit Sub
    End If
    
    If NewPassword = "" Then
        prompt$ = "You must generate or type in a new password before proceeding."
        reply = MsgBox(prompt$, , "Confirm Selection")
            If reply = vbOK Then Exit Sub
    End If
     
    selectedusername = Combo1.Text
    SelectedServerName = DataCombo1.BoundText
    
    sql = "select server_table.customername, username_table.servername, username_table.username, username_table.password from server_table inner join username_table on server_table.servername = username_table.servername where username_table.servername = '" & SelectedServerName & "' and username_table.username = '" & selectedusername & "'"
    'sql = "select * from username_table where servername ='" & SelectedServerName & "'" & " and username ='" & selectedusername & "'"
    rs.Open sql, dbs, adOpenDynamic, adLockReadOnly
    ReturnedCustomerName = rs("customername")
    rs.Close

    prompt$ = "Please confirm the server and customer name below before proceeding:" & WrapCharacter$ & WrapCharacter$ _
        & SelectedServerName & "      " & selectedusername & "      " & ReturnedCustomerName _
        & WrapCharacter$ & WrapCharacter$ & "Click OK if correct, Cancel if incorrect!"
    reply = MsgBox(prompt$, vbOKCancel, "Confirm Selection")
    If reply = vbOK Then
        prompt2$ = "Please confirm the details below, then press 'OK' to change the password or 'Cancel' to quit." _
            & WrapCharacter$ & WrapCharacter$ _
            & "     " & ReturnedCustomerName & "       " & SelectedServerName & "       " _
            & selectedusername & "       " & ReturnedPassword _
            & WrapCharacter$ & WrapCharacter$ & "with " _
            & WrapCharacter$ & WrapCharacter$ _
            & "     " & ReturnedCustomerName & "       " & SelectedServerName & "       " _
            & selectedusername & "       " & NewPassword
        reply2 = MsgBox(prompt2$, vbOKCancel, "Confirm Selection")
            If reply2 = vbOK Then
                sql = "update username_table set password = '" & NewPassword _
                    & "' where servername = '" & SelectedServerName _
                    & "' and username = '" & selectedusername & "'"
                rs.Open sql, dbs, adOpenDynamic, adLockReadOnly
                rs.Close
            End If
        
    End If
    
End Sub
Reply With Quote
  #3  
Old 05-28-2002, 08:11 AM
Road Runner Road Runner is offline
Contributor
 
Join Date: Feb 2002
Location: Ireland
Posts: 444
Default

Did you try this method

dbs.Execute sql
__________________

"All i know is i don't know and i don't even know that!"
Reply With Quote
  #4  
Old 05-28-2002, 08:13 AM
intersimi
 
Posts: n/a
Default

I will try that method.


The actual SQL from the debug info is

Code:
"update username_table set password = ';5J3q+EB5H>U=^' where servername = 'servername1' and username = 'username1'"
Reply With Quote
  #5  
Old 05-28-2002, 08:15 AM
intersimi
 
Posts: n/a
Default

Same issue with the:
Code:
dbs.Execute sql
Method.
Reply With Quote
  #6  
Old 05-28-2002, 08:18 AM
Road Runner Road Runner is offline
Contributor
 
Join Date: Feb 2002
Location: Ireland
Posts: 444
Default

is it just not updating correctly or is it giving you an error message
__________________

"All i know is i don't know and i don't even know that!"
Reply With Quote
  #7  
Old 05-28-2002, 08:50 AM
intersimi
 
Posts: n/a
Default

I get a:

Quote:
Run-time error '2147217900 (80040e14)':

Syntax error in UPDATE statement.
Reply With Quote
  #8  
Old 05-28-2002, 08:53 AM
Thinker Thinker is offline
Iron-Fisted Programmer
Retired Moderator
* Guru *
 
Join Date: Jul 2001
Location: Fayetteville Arkansas USA
Posts: 18,127
Default

Your SQL looks fine, so I would try putting some fields inside of []
Code:
"update username_table set [password] = ';5J3q+EB5H>U=^' where [servername] = 'servername1' and [username] = 'username1'"
__________________
Posting Guidelines
Reply With Quote
  #9  
Old 05-28-2002, 08:56 AM
Road Runner Road Runner is offline
Contributor
 
Join Date: Feb 2002
Location: Ireland
Posts: 444
Default

Here is what Microsoft have to say on the matter.
__________________

"All i know is i don't know and i don't even know that!"
Reply With Quote
  #10  
Old 05-28-2002, 09:05 AM
intersimi
 
Posts: n/a
Default

Thanks a million guys. Thinkers idea payed off. I think it was the "password" field that threw it a little. adding the square brackets worked a treat.

I seem to remember having this problem a while back.

Thanks again everyone.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Advertisement: