Hi all,
I am using DataReader for the first time and i faced more than one error and this is the last one
((Index was outside the bounds of the array.))
and it's point to this line
Dim result As Data.SqlClient.SqlDataReader = dr(Data.CommandBehavior.CloseConnection)
I think I have problem with closing the data reader but I tried several things and its still not working
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 & "') "
MyComm.CommandText = "SELECT * FROM LoginTable WHERE (loginId ='" & TextBox1.Text & "') AND (Password = '" & TextBox2.Text & "') "
sqlconnet.Open()
dr = MyComm.ExecuteReader()
dr.Read()
logID = dr.ToString(0)
PassW = dr.ToString(1)
Admin = dr.ToString(2)
SLP = dr.ToString(3)
Pateint = dr.ToString(4)
UserType = dr.ToString(5)
Dim result As Data.SqlClient.SqlDataReader = dr(Data.CommandBehavior.CloseConnection)
If result.HasRows = False Then
MsgBox("Error")
ElseIf result.HasRows = True And UserType = "S" Then
' Session("logAccount") = TextBox3.Text
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
Plz help me !!!