VB Problems

Status
Not open for further replies.

mickeymouse

Solid State Member
Messages
7
Hi to all, I am facing the below problems. I do not know why did the program went wrong, i just can't get it to debut.


The codes: (login.aspx)
Private Sub ImageButton1_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click
Dim strUser, strPwd As String
Dim retrieveUser, retrievePwd As String

strUser = txtUser.Text
strPwd = txtPwd.Text

Dim objDBMgmt As New DbMgmt
objDBMgmt.Connect()

Dim strSqlCmd As String
strSqlCmd = "Select UserId From User where UserId = '" & strUser & "'"
retrieveUser = objDBMgmt.ExecuteScalar(strSqlCmd)

strSqlCmd = "Select Password From User where Password = '" & strPwd & "'"
retrievePwd = objDBMgmt.ExecuteScalar(strSqlCmd)

If strUser = retrieveUser And strPwd = retrievePwd Then
Session("UserId") = retrieveUser
Session("Password") = retrievePwd
Response.Redirect("Home.aspx")
'invalid account
Else
lblErrMsg.Text = "Incorrect Email and password"
lblErrMsg.ForeColor = Color.Red
End If



'redirect to successful page
objDBMgmt.Close()


End Sub

Below is the extract of the error and i do not understand what it means.



The errors:
Server Error in '/VirtualSociety' Application.

Syntax error in FROM clause.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.OleDb.OleDbException: Syntax error in FROM clause.

Source Error:
Line 112:Line 113: sqlCmd.CommandText = cmdLine 114: value = sqlCmd.ExecuteScalar()Line 115:Line 116: Return value

Source File: c:\inetpub\wwwroot\VirtualSociety\DbMgmt.vb Line: 114

Stack Trace:
[OleDbException (0x80040e14): Syntax error in FROM clause.] System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr) System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) System.Data.OleDb.OleDbCommand.ExecuteScalar() VirtualSociety.DbMgmt.ExecuteScalar(String cmd) in c:\inetpub\wwwroot\VirtualSociety\DbMgmt.vb:114 VirtualSociety.Login.ImageButton1_Click(Object sender, ImageClickEventArgs e) in c:\inetpub\wwwroot\VirtualSociety\Login.aspx.vb:49 System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e) System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) System.Web.UI.Page.ProcessRequestMain()
 
im not really too sure about VB as I havent had much experience with it but those quotes around the sql statements look wrong

strSqlCmd = "Select UserId From User where UserId = '" & strUser & "'"
strSqlCmd = "Select Password From User where Password = '" & strPwd & "'"


did you try removing the single quotes

strSqlCmd = "Select UserId From User where UserId = " & strUser & ""
strSqlCmd = "Select Password From User where Password = " & strPwd & ""
 
VB problems

Thanks for the reply. I am hoping for more solutions to come in. Maybe other ways of writing the codes. This is urgent. Thanks
 
hey i think the single quotes an dthe double quotes are for the charecters so if its a string which is passed, then ull have those strings...

with regd to the code snippet.. why dont we create a function for the connection or try declaring the conection object globally which wud be of more usage .....

like
option explicit

dim db as new db.connection and stuff i think it shud work if this done...
 
Status
Not open for further replies.
Back
Top Bottom