Hi pple

I've using visual studio 2005 and sql server 2005.

I've stored my usernames and passwords in the database. Now i have problems on how to use select statements to check username. Meaning. if username is not found, it gives error msg, if username exist, it compares with the password. I'm using datareader to do this. Please guide me through this.

Actually, there will be dropDownList too. After the user enters the username, password and choose one of the option in the dropDownList, the system does the checking and if login successful, the user will be directed to the selected option.

What i mean is that, for an eg, there will be options like IT,CDS and MWC. There will be 1 panel and Im using label to identify the options. So, if user choose IT, i should be able to redirect the page to the IT panel. I hope my explanation is clear...please help me..

Advance thanks.

nandhini

actually you didn't show your code so far.
Try this following code :

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Conn As SqlConnection
        Dim myReader As SqlDataReader
        Dim myReader2 As SqlDataReader
        Dim myUser As String

        Conn = GetConnect()
        Conn.Open()
        Dim sql As String = "SELECT * From Users where Id_User='" & txtUserId.Text & "'"
        Dim command As SqlCommand = New SqlCommand(sql, Conn)
        myReader = command.ExecuteReader


        If myReader.HasRows Then
            While myReader.Read
                myUser = myReader.Item("Id_User")
            End While
            myReader.Close()
        End If

        If txtUserId.Text = myUser Then
            MsgBox(myUser)
        Else
            MsgBox("User Id Not Available")
        End If
        Conn.Close()
    End Sub

Thanks for your reply Jx_Man.
But if i use this code, how to i check for password. I believe after checking for username and password, I got to code for dropDownList seperately and redirect the page accordingly. I'm not sure how to do that.

This is what I've tried doing..

Protected Sub btnLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLogin.Click


Dim StaffId As String
Dim MCODE As String
Dim dat As String
Dim Tam As String
Dim dtNow As String
Dim sqlConn As SqlConnection
Dim SqlCommand As SqlCommand
Dim MyReader As SqlDataReader
Dim MyReader2 As SqlDataReader
Dim sql As String
Dim SQLString As String
Dim success As Boolean = False


dtNow = Now
dat = FormatDateTime(dtNow, vbShortDate)

Tam = FormatDateTime(dtNow, vbLongTime)

StaffId = txtUsername.Text
MCODE = DropDownList1.Text

SqlCommand.Connection.Open()


sqlConn = New SqlConnection("Data Source=localhost;Initial Catalog=Queue;Integrated Security=True")

SQLString = "SELECT *" & _ "FROM StaffLogin" & " where StaffId ='" &txtUsername.Text&"' " & _ " AND password = '"&txtPwd.Text&"'"
Dim sqlcmd As New System.Data.SqlClient.SqlCommand(sql, sqlConn)
MyReader = SqlCommand.ExecuteReader()

If MyReader.HasRows Then
success = True
End If
MyReader.Close()
sqlcmd.Dispose()
sqlConn.Close()
If success Then

End If


SqlCommand.Connection.Close()


sql = "INSERT INTO StaffInfo(StaffId, queueOpt, [LoginDate], [LoginTime]) Values'" & StaffId & "', '" & MCODE & "'," & dat & "','" & Tam & "'"
SqlCommand = New SqlCommand(sql, sqlConn)

SqlCommand = New SqlCommand("Select * from StaffLogin", sqlConn)

SqlCommand.ExecuteNonQuery()
SqlCommand.Connection.Close()
sqlConn.Open()


End Sub

sorry.. i think the arragements of open and close connection is wrong..

Please guide me through on how to get this done...thanks alot..

Dim dr As SqlDataReader

Dim qu As New SqlCommand("select uname from users where code ='" + TextBox1.Text.Trim() + "'", con)

dr = qu.ExecuteReader()

Dim sus As Boolean = (dr.Read() AndAlso dr.GetString(0) = TextBox2.Text.Trim())

If Not sus Then
Label4.Text = "No Account"

con.Close()

Else
Label4.Text = "You are the one"
con.Close()
End If

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.