I am working on the development of login screen. For user entered UserName and Password , I am checking if they exist in the database table called user_mstr. I have added the follwing code as Action event for Login button. But during run-time error with a bug symbol at the begining of the Bind-Type statement as shown in the code below. Can anyone help resolve this. If possible give me any simple code to validate the entered user-id and password against the table values. Thank you.
Sub Action()
Dim ps As PreparedSQLStatement = _
ssssterp.Prepare(“SELECT * FROM user_mstr WHERE Name = ? AND Password = ?”)
ps.BindType(0, MySQLPreparedStatement.MYSQL_TYPE_STRING) /******** Error line **************/
ps.BindType(1, MySQLPreparedStatement.MYSQL_TYPE_STRING)
Dim rs As RecordSet = ps.SQLSelect
If rs <> Nil Then
While Not rs.EOF
MsgBox("Name: " + rs.Field(“Name”).StringValue + " Password: " + rs.Field(“Password”).StringValue)
rs.MoveNext
Wend
Else
If ssssterp.Error Then MsgBox(ssssterp.ErrorMessage)
End If
End Sub
Hi Greg,
Sorry, now I added correctly as you said, but I am getting the following error
Login.LoginButton.Action, line 2
Type mismatch error. Expected class MySQLPreparedStatement, but got interface PreparedSQLStatement
ssssterp.Prepare(“SELECT * FROM user_mstr WHERE Name = ? AND Password = ?”)
Apologies for late reply. Thank you all for your help. I was 4 days away from work.
The query from Jeff ’ Where and how is ssssterp defined and initialsed’ help me to probe further the Database concepts documents in xojo. Then I understood since the database was added to the project, it has to cast the result from db.prepare. It is working fine now.
Here is my revised code…
Note:'This example uses a MySQL Database that was added to the project, so it has to cast the result from db.Prepare.
Dim ps As PreparedSQLStatement
here is the corrected statement below…
ps = MYSQLPreparedStatement(ssssterp.Prepare(“SELECT * FROM user_mstr WHERE Name = ? AND Password = ?”))
Dim rs As RecordSet = ps.SQLSelect
If rs <> Nil Then
IF rs.Field(“Name”).StringValue = UserNameText.Text AND rs.Field(“Password”).StringValue = PasswordText.Text AND UserNameText.Text <> “” AND PasswordText.Text <> “” THEN
'While Not rs.EOF
'MsgBox("Name: " + rs.Field(“Name”).StringValue + " Password: " + rs.Field(“Password”).StringValue)
'rs.MoveNext
'Wend
Login.close
Menu.show
Else
Msgbox(“Invalid UserId or Password…Please Retry”)
UserNameText.SetFocus()
rs.close
END IF
Else
If ssssterp.Error Then MsgBox(ssssterp.ErrorMessage)
rs.close
End If