| | |
Datareader...i need help urgently...
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jan 2008
Posts: 7
Reputation:
Solved Threads: 0
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
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 :
Try this following code :
vb Syntax (Toggle Plain Text)
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
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
So, Please do something before post your thread.
* PM Asking will be ignored *
•
•
Join Date: Jan 2008
Posts: 7
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: May 2008
Posts: 9
Reputation:
Solved Threads: 0
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
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
![]() |
Similar Threads
- I need help..urgently (VB.NET)
Other Threads in the VB.NET Forum
- Previous Thread: [B] Need help editing sequential file[B]
- Next Thread: vb.net to connect sql so that .................
| Thread Tools | Search this Thread |
.net .net2008 2005 2008 access account application arithmetic array basic bing button buttons center check code combobox component crystalreport data database datagrid datagridview date design dissertation dissertations dropdownlist excel fade file-dialog filter ftp generatetags google gridview hardcopy hosting images input insert intel internet listview mobile monitor ms net networking objects output panel passingparameters peertopeervideostreaming picturebox picturebox1 port position print printing problem problemwithinstallation project remove save searchbox searchvb.net select serial shutdown soap survey table tcp temperature text textbox timer timespan toolbox trim update updown user vb vb.net vb.netcode vb.netformclosing()eventpictureboxmessagebox vb2008 vbnet view visual visualbasic visualbasic.net visualstudio visualstudio2008 web winforms wpf year






