Datareader...i need help urgently...

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Jan 2008
Posts: 7
Reputation: nandhini21 is an unknown quantity at this point 
Solved Threads: 0
nandhini21 nandhini21 is offline Offline
Newbie Poster

Datareader...i need help urgently...

 
0
  #1
Feb 11th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 2,641
Reputation: Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light 
Solved Threads: 245
Jx_Man's Avatar
Jx_Man Jx_Man is offline Offline
Posting Maven

Re: Datareader...i need help urgently...

 
0
  #2
Feb 11th, 2008
actually you didn't show your code so far.
Try this following code :
  1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2. Dim Conn As SqlConnection
  3. Dim myReader As SqlDataReader
  4. Dim myReader2 As SqlDataReader
  5. Dim myUser As String
  6.  
  7. Conn = GetConnect()
  8. Conn.Open()
  9. Dim sql As String = "SELECT * From Users where Id_User='" & txtUserId.Text & "'"
  10. Dim command As SqlCommand = New SqlCommand(sql, Conn)
  11. myReader = command.ExecuteReader
  12.  
  13.  
  14. If myReader.HasRows Then
  15. While myReader.Read
  16. myUser = myReader.Item("Id_User")
  17. End While
  18. myReader.Close()
  19. End If
  20.  
  21. If txtUserId.Text = myUser Then
  22. MsgBox(myUser)
  23. Else
  24. MsgBox("User Id Not Available")
  25. End If
  26. Conn.Close()
  27. End Sub
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 7
Reputation: nandhini21 is an unknown quantity at this point 
Solved Threads: 0
nandhini21 nandhini21 is offline Offline
Newbie Poster

Re: Datareader...i need help urgently...

 
0
  #3
Feb 11th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 7
Reputation: nandhini21 is an unknown quantity at this point 
Solved Threads: 0
nandhini21 nandhini21 is offline Offline
Newbie Poster

Re: Datareader...i need help urgently...

 
0
  #4
Feb 11th, 2008
sorry.. i think the arragements of open and close connection is wrong..

Please guide me through on how to get this done...thanks alot..
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 9
Reputation: aastephen is an unknown quantity at this point 
Solved Threads: 0
aastephen aastephen is offline Offline
Newbie Poster

Re: Datareader...i need help urgently...

 
0
  #5
May 27th, 2008
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the VB.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC