Click here to Skip to main content
15,896,306 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi im new in this programming language.. im currently working on a Log In system where there are 3 inputs; Username, Password and Position
my problem is when accessing only 2 inputs(Username, Password) the program works fine but when it is 3 some error occured.
Ive tried google, and other search engine but they are only for two inputs plss help me..
Here is my code
<pre lang="xml"><%@ Page Language="VB" Debug="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System.Web.UI" %>

<script language="VB" runat="server">

    Sub btnLogin_OnClick(Src As Object, E As EventArgs)
        Dim myConnection  As OleDbConnection
        Dim myCommand     As OleDbCommand
        Dim strUserURL    As String
        Dim strSQL        As String

        strSQL = "SELECT destination FROM tblLoginInfo " _
         & "WHERE username='" & Replace(txtUsername.Text, "'", "''") & "' " _
         & "AND password='" & Replace(txtPassword.Text, "'", "''") & "';" _
         & "AND position='" & Replace(items.Text, "'", "'") & "';"

        myConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; " _
            & "Data Source=" & Server.MapPath("login.mdb") & ";")

        myCommand = New OleDbCommand(strSQL, myConnection)

        myConnection.Open()
        strUserURL = myCommand.ExecuteNonQuery()
        myConnection.Close()

        'Response.Write(intUserCount)
        If strUserURL <> "" Then
            lblInvalid.Text = ""
            FormsAuthentication.SetAuthCookie(txtUsername.Text, True)
            Response.Redirect("bob.aspx")
        Else
            lblInvalid.Text = "Sorry... try again..."
        End If
    End Sub

</script>

<html>
<head>
<title>ASP.NET Login</title>
</head>
<body>

<h2>Please Login:</h2>

<p>
Hint:
</p>

<p>
<asp:Label id="lblInvalid" runat="server" />
</p>

<form runat="server">

    Username: <asp:TextBox id="txtUsername" runat="server" /><br />
    Password: <asp:TextBox id="txtPassword" TextMode="password" runat="server" /><br />
    <br />
    <br />
    <br />
    position: <asp:TextBox id="items" runat="server" /><br />
    <br />
    <br />
    <asp:Button id="btnLogin" runat="server"
        text="Login" OnClick="btnLogin_OnClick" Width="221px"
    />
</form>


<p>
If you're not sure who you are currently logged in as you can
always check via the <a href="whoami.aspx">Who Am I?</a> page.
</p>

</body>
</html>



Here is the problem when i connect it to local host:
<pre lang="msil">IErrorInfo.GetDescription failed with E_FAIL(0x80004005).
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: IErrorInfo.GetDescription failed with E_FAIL(0x80004005).

Source Error:


Line 23:
Line 24:        myConnection.Open()
Line 25:         strUserURL = myCommand.ExecuteScalar()
Line 26:        myConnection.Close()
Line 27:

Posted

1 solution

Not sure if this can help but I saw your code and found out that you have a semicolon on the 3rd line. I think you should remove it. Hope it helps.

strSQL = "SELECT destination FROM tblLoginInfo " _
        & "WHERE username='" & Replace(txtUsername.Text, "'", "''") & "' " _
        & "AND password='" & Replace(txtPassword.Text, "'", "''") & "';" _
        & "AND position='" & Replace(items.Text, "'", "'") & "';"
 
Share this answer
 
Comments
drkterror1 26-Apr-11 21:30pm    
Sir it still wont work I even try deleting the two semicolons but it still dont work i eve tried to chane it to .executescalar but the error still pops out ..
but thanks for the help and time really appreciate it ^^
walterhevedeich 26-Apr-11 22:05pm    
Same error?
drkterror1 26-Apr-11 22:27pm    
Yes
walterhevedeich 26-Apr-11 22:33pm    
Are you sure you posted the right code? I saw in your Source Error that it has a ExecuteScalar method but I can't see that in your code. All I see is ExecuteNonQuery.
drkterror1 26-Apr-11 22:29pm    
i even change the query it becomes "Select * from tblLoginInfo"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900