Question:

Syntax error in vb ?

by  |  earlier

0 LIKES UnLike

am using the folling piece of code....the error which am getting id syntax error in update staement..........but am unable to rectify it..please helep asap

Dim strQry As String

strQry = "update Table1 set login_name = " & newusername.Text & ", password = " & newpassword.Text & " where id = " & currid1

myConnection.Execute (strQry)

MsgBox ("A recorded has been updated to the database")

End Sub

Private Sub cmdCancel_Click()

Unload Me

End Sub

Private Sub cmdOK_Click()

Dim sqlStr As String

Dim temp As String

Dim temp1 As String

Dim rsData As ADODB.Recordset

sqlStr = "select * from Table1 where login_name='" & txtUserName.Text & "'"

Set rsData = New ADODB.Recordset

rsData.Open sqlStr, myConnection, adOpenStatic, adLockReadOnly

currid1 = rsData.Fields.Item(0)

temp = rsData.Fields.Item(1)

temp1 = rsData.Fields.Item(2)

If txtUserName.Text = temp And txtPassword.Text = temp1 Then

'Me.Hide

'Form2.Show

continue.Visible = True

change.Visible = True

changepassword.Visible = True

newpassword.Visible = True

changeusername.Visible = True

newusername.Visible = True

Else

MsgBox "invalid login_id or password"

End If

rsData.Close

End Sub

Private Sub Form_Load()

Set myConnection = New ADODB.Connection

myConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & App.Path & "\\password.mdb"

myConnection.Open

End Sub

 Tags:

   Report

1 ANSWERS


  1. you have to enclose your values for your UPDATE statement in single quotes. ( ' ). newUser.Text & newPassword.Text should be enclosed in quotes. if Your id field is non-numeric then you have to enclosed it in single quotes too.

    strQry = "update Table1 set login_name = '" & newusername.Text & "', password = '" & newpassword.Text & "' where id = " & currid1

    - SAME AS your query for SELECT where you enclosed it in single quotes..

    sqlStr = "select * from Table1 where login_name='" & txtUserName.Text & "'"

    hope this helps

You're reading: Syntax error in vb ?

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.