Click here to Skip to main content
15,906,081 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi.i am sandhya.i want to acces login page hen i gv only user specified userid and pwd .otherthan login page uerid and pwd,it will display error msg.
the code is
VB
Imports System.Data.OleDb

Partial Class Default2
    Inherits System.Web.UI.Page

    Private Property UserName As Object

    Private Property auth As Boolean



    Private Property txtPwd As Object

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim connString As String = "Data Source=C:\Users\Administrator\Desktop\login.mdb;Provider=Microsoft.Jet.OleDb.4.0"
        Dim qryString As String = "SELECT username, password FROM login;"
        Dim objConn As New OleDbConnection(connString)
        Dim objCmd As New OleDbCommand(qryString, objConn)
        Dim myReader As OleDbDataReader

        Try

            Dim gotUser As Boolean = False
            objConn.Open()
            myReader = objCmd.ExecuteReader

            While myReader.Read
               .. If myReader.Item("username") = UserName.Text Then.. ' This is the error line
                    gotUser = True
                    auth = CheckPwd(myReader.Item("username"), myReader.Item("password"))
                End If

            End While
            If gotUser = False Then
                Label3.Text = "You are not authorized for access"
            Else
                Select Case auth
                    Case True
                        FormsAuthentication.RedirectFromLoginPage(UserName.Text, False)
                    Case Else
                        Label3.Text = "Incorrect Password"
                End Select
            End If

        Catch ex As Exception

            Label3.Text = ex.ToString

        Finally
            objConn.Close()
        End Try
        
    End sub

    Public Function CheckPwd(ByVal username As String, ByVal password As String) As Boolean

        Dim Authorized As Boolean = False
        Dim pwdFromUser As String = txtPwd.Text

        If pwdFromUser = password Then
            Authorized = True
        Else
            Authorized = False
        End If

        Return Authorized

    End Function

End Class


at ... line i got the error as

System.NullReferenceException: Object variable or With block variable not set. at Microsoft.VisualBasic.CompilerServices.Symbols.Container..ctor(Object Instance) at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateGet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack) at Default2.Button1_Click(Object sender, EventArgs e) in C:\Users\Administrator\Documents\Visual Studio 2010\WebSites\WebSite9\Default2.aspx.vb:line 28

pls help me
Posted
Updated 19-Dec-13 22:36pm
v4
Comments
Sugu.s 20-Dec-13 4:33am    
Replace your Query string as "SELECT ISNULL(username,'') AS username, ISNULL(password,'') AS username FROM login;"
Member 10478580 20-Dec-13 4:37am    
System.Data.OleDb.OleDbException (0x80040E14): Wrong number of arguments used with function in query expression 'ISNULL(username,'')'. at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) at System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior) at System.Data.OleDb.OleDbCommand.ExecuteReader() at Default2.Button1_Click(Object sender, EventArgs e) in C:\Users\Administrator\Documents\Visual Studio 2010\WebSites\WebSite9\Default2.aspx.vb:line 25
again i got this ..
Ashish_Agrawal 20-Dec-13 4:34am    
which one is line 28 in your code?
Member 10478580 20-Dec-13 4:35am    
it is started with .. and ends with ..
Gitanjali Singh 20-Dec-13 4:36am    
In the line .. If myReader.Item("username") = UserName.Text Then.., why you have added .. after and before line?
If you have added it by mistake , remove this.

1 solution

okay try using username.ToString() method rather than username.Text . i see that you define user property as object so i think you need to cast it as a string using Tostring Method. also i see that you did not assign value to the username object, write get set for object username and set

username = "somename";

hope this help to you.
 
Share this answer
 

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