Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > sqlreader.GetValue(sqlreader.GetOrdinal(columnname ) problem

Reply
Thread Tools

sqlreader.GetValue(sqlreader.GetOrdinal(columnname ) problem

 
 
=?Utf-8?B?YzY3NjIyOA==?=
Guest
Posts: n/a
 
      02-24-2006
Hi all,
I am stuck with this problem.
the code is like this:
Dim sqlreader As SqlDataReader =
myCommand.ExecuteReader(CommandBehavior.CloseConne ction)

sqlreader.GetValue(sqlreader.GetOrdinal(columnname ) give me the following in
the watch window:

sqlreader.GetValue(sqlreader.GetOrdinal("enrolldat e")) Run-time exception
thrown : System.InvalidOperationException - Invalid attempt to read when no
data is present.
But I can get the column number: sqlreader.GetOrdinal("enrolldate") is 1.
What's going on?
Thank you.
Betty





--
Betty
 
Reply With Quote
 
 
 
 
Brian
Guest
Posts: n/a
 
      02-24-2006
Do you call sqlreader.Read() before trying to get a value? No rows are
fetched until you do this.

 
Reply With Quote
 
 
 
 
=?Utf-8?B?YzY3NjIyOA==?=
Guest
Posts: n/a
 
      02-24-2006
When I look at the sqlreader in the watch window, it gave the following info:

Depth 0 Integer
FieldCount 62 Integer
HasRows True Boolean
IsClosed False Boolean
Item <cannot view indexed property> Object
RecordsAffected -1 Integer

So that means I pull the data through the procedure, right.
--
Betty


"c676228" wrote:

> Hi all,
> I am stuck with this problem.
> the code is like this:
> Dim sqlreader As SqlDataReader =
> myCommand.ExecuteReader(CommandBehavior.CloseConne ction)
>
> sqlreader.GetValue(sqlreader.GetOrdinal(columnname ) give me the following in
> the watch window:
>
> sqlreader.GetValue(sqlreader.GetOrdinal("enrolldat e")) Run-time exception
> thrown : System.InvalidOperationException - Invalid attempt to read when no
> data is present.
> But I can get the column number: sqlreader.GetOrdinal("enrolldate") is 1.
> What's going on?
> Thank you.
> Betty
>
>
>
>
>
> --
> Betty

 
Reply With Quote
 
=?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
Guest
Posts: n/a
 
      02-24-2006
Enclose your code in a while loop like this:

While sqlreader.Read()
'place the code to GetValue here
End While

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


"c676228" wrote:

> Hi all,
> I am stuck with this problem.
> the code is like this:
> Dim sqlreader As SqlDataReader =
> myCommand.ExecuteReader(CommandBehavior.CloseConne ction)
>
> sqlreader.GetValue(sqlreader.GetOrdinal(columnname ) give me the following in
> the watch window:
>
> sqlreader.GetValue(sqlreader.GetOrdinal("enrolldat e")) Run-time exception
> thrown : System.InvalidOperationException - Invalid attempt to read when no
> data is present.
> But I can get the column number: sqlreader.GetOrdinal("enrolldate") is 1.
> What's going on?
> Thank you.
> Betty
>
>
>
>
>
> --
> Betty

 
Reply With Quote
 
sloan
Guest
Posts: n/a
 
      02-24-2006

As other people has previous posted:
http://www.lhotka.net/cslacvs/viewcv...eDataReader.vb

this SafeDataReader has these built in checks for you.

But... yes, you have to call the Read() method ... and put your code in the
Read() loop ....

Its kinda like "If not rs.EOF".. but its not quite that exactly either.

...

The SafeDataReader is a nice bit of code to make the IDataReader a little
easier to deal with.





"c676228" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi all,
> I am stuck with this problem.
> the code is like this:
> Dim sqlreader As SqlDataReader =
> myCommand.ExecuteReader(CommandBehavior.CloseConne ction)
>
> sqlreader.GetValue(sqlreader.GetOrdinal(columnname ) give me the following

in
> the watch window:
>
> sqlreader.GetValue(sqlreader.GetOrdinal("enrolldat e")) Run-time exception
> thrown : System.InvalidOperationException - Invalid attempt to read when

no
> data is present.
> But I can get the column number: sqlreader.GetOrdinal("enrolldate") is 1.
> What's going on?
> Thank you.
> Betty
>
>
>
>
>
> --
> Betty



 
Reply With Quote
 
=?Utf-8?B?YzY3NjIyOA==?=
Guest
Posts: n/a
 
      02-24-2006
thank you all. I missed that part .
--
Betty


"sloan" wrote:

>
> As other people has previous posted:
> http://www.lhotka.net/cslacvs/viewcv...eDataReader.vb
>
> this SafeDataReader has these built in checks for you.
>
> But... yes, you have to call the Read() method ... and put your code in the
> Read() loop ....
>
> Its kinda like "If not rs.EOF".. but its not quite that exactly either.
>
> ...
>
> The SafeDataReader is a nice bit of code to make the IDataReader a little
> easier to deal with.
>
>
>
>
>
> "c676228" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Hi all,
> > I am stuck with this problem.
> > the code is like this:
> > Dim sqlreader As SqlDataReader =
> > myCommand.ExecuteReader(CommandBehavior.CloseConne ction)
> >
> > sqlreader.GetValue(sqlreader.GetOrdinal(columnname ) give me the following

> in
> > the watch window:
> >
> > sqlreader.GetValue(sqlreader.GetOrdinal("enrolldat e")) Run-time exception
> > thrown : System.InvalidOperationException - Invalid attempt to read when

> no
> > data is present.
> > But I can get the column number: sqlreader.GetOrdinal("enrolldate") is 1.
> > What's going on?
> > Thank you.
> > Betty
> >
> >
> >
> >
> >
> > --
> > Betty

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem problem problem :( Need Help Mike ASP General 2 05-11-2004 08:36 AM



Advertisments