I'm trying to put together a web form that lists all current session informa
tion. The session info is stored in SQL server database (ASPState) and I'm t
rying to retreive and display using a SQLDataReader. I seem to have no troub
le querying the "ASPStateTe
mpSessions" table but when I try to write it to the page, I throw an excepti
on that basically says that there is no data to display. Is there some speci
al method you must use when performing this sort of task?
The code is as follows:
----
dim cn as new SqlConnection(ConfigurationSettings.AppSetting ("ASPState").to
String())
cn.Open()
dim cmd as new SqlCommand("select * from ASPStateTempSessions where TimeOut
= 40", cn)
dim dr as SqlDataReader
dr = cmd.ExecuteReader()
Response.Write(dr("Locked"))
----
The exception content is as follows:
System.InvalidOperationException: Invalid attempt to read when no data is pr
esent. at System.Data.SqlClient.SqlDataReader.PrepareRecord(Int32 i) at Syst
em.Data.SqlClient.SqlDataReader.GetValue(Int32 i) at System.Data.SqlClient.S
qlDataReader.get_Item(Strin
g name) at ASP.AgreementListing_aspx.Page_Load(Object Sender, EventArgs E) i
n C:\Inetpub\wwwroot\onehour\AgreementList
ing.aspx:line 82when using a datareader, you have to first call the "read" method.
dr = cmd.ExecuteReader()
dr.read()
Response.Write(dr("Locked"))
OR to get all rows:
do while dr.read()
Response.Write(dr("Locked"))
loop (i think)
"Glenn Venzke" <GlennVenzke@.discussions.microsoft.com> wrote in message
news:BBA23A84-4649-4967-8AA3-6D98648C0555@.microsoft.com...
> I'm trying to put together a web form that lists all current session
information. The session info is stored in SQL server database (ASPState)
and I'm trying to retreive and display using a SQLDataReader. I seem to have
no trouble querying the "ASPStateTempSessions" table but when I try to write
it to the page, I throw an exception that basically says that there is no
data to display. Is there some special method you must use when performing
this sort of task?
> The code is as follows:
> ----
> dim cn as new SqlConnection(ConfigurationSettings.AppSetting
("ASPState").toString())
> cn.Open()
> dim cmd as new SqlCommand("select * from ASPStateTempSessions where
TimeOut = 40", cn)
> dim dr as SqlDataReader
> dr = cmd.ExecuteReader()
> Response.Write(dr("Locked"))
>
> ----
> The exception content is as follows:
> System.InvalidOperationException: Invalid attempt to read when no data is
present. at System.Data.SqlClient.SqlDataReader.PrepareRecord(Int32 i) at
System.Data.SqlClient.SqlDataReader.GetValue(Int32 i) at
System.Data.SqlClient.SqlDataReader.get_Item(String name) at
ASP.AgreementListing_aspx.Page_Load(Object Sender, EventArgs E) in
C:\Inetpub\wwwroot\onehour\AgreementList
ing.aspx:line 82
Boy, am I a dope! I thought datareader.read worked along the lines of record
set.EOF. I thought it was a simple boolean property that told you if any rec
ords were returned or not. But it is actually a method that returns a boolea
n. I guess you learn someth
ing new every day. Thanks much!!
"mark" wrote:
> when using a datareader, you have to first call the "read" method.
> dr = cmd.ExecuteReader()
> dr.read()
> Response.Write(dr("Locked"))
> OR to get all rows:
> do while dr.read()
> Response.Write(dr("Locked"))
> loop (i think)
>
>
> "Glenn Venzke" <GlennVenzke@.discussions.microsoft.com> wrote in message
> news:BBA23A84-4649-4967-8AA3-6D98648C0555@.microsoft.com...
> information. The session info is stored in SQL server database (ASPState)
> and I'm trying to retreive and display using a SQLDataReader. I seem to ha
ve
> no trouble querying the "ASPStateTempSessions" table but when I try to wri
te
> it to the page, I throw an exception that basically says that there is no
> data to display. Is there some special method you must use when performing
> this sort of task?
> ("ASPState").toString())
> TimeOut = 40", cn)
> present. at System.Data.SqlClient.SqlDataReader.PrepareRecord(Int32 i) at
> System.Data.SqlClient.SqlDataReader.GetValue(Int32 i) at
> System.Data.SqlClient.SqlDataReader.get_Item(String name) at
> ASP.AgreementListing_aspx.Page_Load(Object Sender, EventArgs E) in
> C:\Inetpub\wwwroot\onehour\AgreementList
ing.aspx:line 82
>
>
0 comments:
Post a Comment