I get a mysterious error when I try to read a datareader:
I have an sql statement and when I execute it it sqlserver management studio I get one row. And when I try with the datareader I get the: Invalid attempt to read data when reader is closed.
SqlConn = New SqlConnection(ConfigurationSettings.AppSettings.Item("ConnectionString"))
SqlConn.Open()
strSQL = "SELECT * FROM MyTable"
dr = New SqlCommand(strSQL, SqlConn).ExecuteReader
If dr.Read() Then
intPeriod = dr("ID")
dCurrentPeriod = dr("StartDate")
end if
dr.Close()
Is anyone could help me with this?
I have an sql statement and when I execute it it sqlserver management studio I get one row. And when I try with the datareader I get the: Invalid attempt to read data when reader is closed.
SqlConn = New SqlConnection(ConfigurationSettings.AppSettings.Item("ConnectionString"))
SqlConn.Open()
strSQL = "SELECT * FROM MyTable"
dr = New SqlCommand(strSQL, SqlConn).ExecuteReader
If dr.Read() Then
intPeriod = dr("ID")
dCurrentPeriod = dr("StartDate")
end if
dr.Close()
Is anyone could help me with this?