Hi all,
I'm trying to get some values from my database using data reader. Its my first time in using dataReader and I have this error
"Value of type 'System.Data.SqlClient.SqlDataReader' cannot be converted to 'String'."
My code
Public Sub LogIn(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim connStr As String = "Data Source=.\SQLEXPRESS;AttachDbFilename='C:\Users\sony\Documents\Visual Studio 2010\Projects\SADA\SADA\App_Data\SADA2.mdf';Integrated Security=True;User Instance=True"
Dim sqlconnet As Data.SqlClient.SqlConnection
Dim MyComm As Data.SqlClient.SqlCommand
Dim dr As SqlDataReader
Dim UserType As String
Dim Pateint As String
Dim SLP As String
Dim Admin As String
Dim logID As String
Dim PassW As String
sqlconnet = New Data.SqlClient.SqlConnection()
sqlconnet.ConnectionString = connStr
MyComm = New Data.SqlClient.SqlCommand("", sqlconnet)
MyComm.CommandType = Data.CommandType.Text
MyComm.CommandText = "SELECT * FROM LoginTable WHERE (loginId ='" & TextBox1.Text & "') AND (Password = '" & TextBox2.Text & "') "
sqlconnet.Open()
dr = MyComm.ExecuteReader()
dr.Read()
logID = dr[0].ToString()
PassW=dr[1].ToString()
Admin=dr[2].ToString()
SLP=dr[3].ToString()
Pateint=dr[4].ToString()
UserType=dr[5].ToString()
Dim result As Data.SqlClient.SqlDataReader = MyComm.ExecuteReader(Data.CommandBehavior.CloseConnection)
If result.HasRows = False Then
MsgBox("Error")
ElseIf result.HasRows = True And UserType = "S" Then
Response.Redirect("SLPMain.aspx")
ElseIf result.HasRows = True And UserType = "A" Then
Response.Redirect("Admin.aspx")
ElseIf result.HasRows = True And UserType = "P" Then
Response.Redirect("WebForm4.aspx")
End If
result.Close()
End Sub
Can anyone help me plz ?!!