473,407 Members | 2,306 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Datareader not working

Hi I am getting a exception while using a datareader here is the code

Me.SqlConnection1.Open()
Me.SqlReservationCheck.Parameters("@Ref").Value = Ref
Dim Reader As SqlClient.SqlDataReader = _
Me.SqlReservationCheck.ExecuteReader()
Dim I As Integer()
Dim Index As Integer = 0
If Reader.HasRows Then
While Reader.Read()
ReDim Preserve I(Index)
I(Index) = Reader.Item(0)
Index += 1
End While
End If
Reader.Close()
Me.SqlConnection1.Close()

When I execute the While Reader.Read() command the reader gives false
But the If Reader.HasRows Then returns true could someone help me with this

--
Later

Scott Richards
Nov 19 '05 #1
10 1832
"Scott Richards" <Sc***********@discussions.microsoft.com> wrote in message
news:38**********************************@microsof t.com...
Hi I am getting a exception while using a datareader here is the code


Which exception do you get, and what line does it happen on?

I really don't know how you expect anyone to be able to help you given the
small amount of information you've provided.

John Saunders
Nov 19 '05 #2
Sorry for the lack of information John, by the time I wrote this I had spent
5 hours researching the problem & was quite frustrated & tired.

The problem is that when I run the datareader.read command the loop does not
intiate because the command gives false

I have checked it by running the datareader.read command without without the
while loop & the information is in the reader, what do you suggest I do?

From all the reading on the subject I have done I have found nothing like
this.

Thank you for your help
--
Later Scott Richards

"John Saunders" wrote:
"Scott Richards" <Sc***********@discussions.microsoft.com> wrote in message
news:38**********************************@microsof t.com...
Hi I am getting a exception while using a datareader here is the code


Which exception do you get, and what line does it happen on?

I really don't know how you expect anyone to be able to help you given the
small amount of information you've provided.

John Saunders

Nov 19 '05 #3
"Scott Richards" <Sc***********@discussions.microsoft.com> wrote in message
news:E7**********************************@microsof t.com...
Sorry for the lack of information John, by the time I wrote this I had
spent
5 hours researching the problem & was quite frustrated & tired.

The problem is that when I run the datareader.read command the loop does
not
intiate because the command gives false


In a case like this, I would first assume that the DataReader is working
correctly. If you start with that assumption, you're left to wonder what you
could possibly have done to make a correctly-functioning DataReader to
return false right away. For instance, are you certain that your query is
correct? If it requires parameters, are they correct? For instance, maybe
you've got a string parameter which has trailing spaces.

John Saunders
Nov 19 '05 #4
Hi John I have checked that the query is returning the correct data by
running the program without the while loop. Is it possible that my datareader
isn't functioning correctly? If so what would you sugest I do. I can find no
other reason why the datareader is returning false straight away.

Scott Richards

"John Saunders" wrote:
"Scott Richards" <Sc***********@discussions.microsoft.com> wrote in message
news:E7**********************************@microsof t.com...
Sorry for the lack of information John, by the time I wrote this I had
spent
5 hours researching the problem & was quite frustrated & tired.

The problem is that when I run the datareader.read command the loop does
not
intiate because the command gives false


In a case like this, I would first assume that the DataReader is working
correctly. If you start with that assumption, you're left to wonder what you
could possibly have done to make a correctly-functioning DataReader to
return false right away. For instance, are you certain that your query is
correct? If it requires parameters, are they correct? For instance, maybe
you've got a string parameter which has trailing spaces.

John Saunders

Nov 19 '05 #5
"Scott Richards" <Sc***********@discussions.microsoft.com> wrote in message
news:C5**********************************@microsof t.com...
Hi John I have checked that the query is returning the correct data by
running the program without the while loop. Is it possible that my
datareader
isn't functioning correctly? If so what would you sugest I do. I can find
no
other reason why the datareader is returning false straight away.
How did running the program without a while loop determine that the data
were correct?

John Saunders

"John Saunders" wrote:
"Scott Richards" <Sc***********@discussions.microsoft.com> wrote in
message
news:E7**********************************@microsof t.com...
> Sorry for the lack of information John, by the time I wrote this I had
> spent
> 5 hours researching the problem & was quite frustrated & tired.
>
> The problem is that when I run the datareader.read command the loop
> does
> not
> intiate because the command gives false


In a case like this, I would first assume that the DataReader is working
correctly. If you start with that assumption, you're left to wonder what
you
could possibly have done to make a correctly-functioning DataReader to
return false right away. For instance, are you certain that your query is
correct? If it requires parameters, are they correct? For instance, maybe
you've got a string parameter which has trailing spaces.

John Saunders

Nov 19 '05 #6
I put a watch on I(0) & got the number that I expected.
I also put a watch on the reader & the next number was in their too.
"John Saunders" wrote:
"Scott Richards" <Sc***********@discussions.microsoft.com> wrote in message
news:C5**********************************@microsof t.com...
Hi John I have checked that the query is returning the correct data by
running the program without the while loop. Is it possible that my
datareader
isn't functioning correctly? If so what would you sugest I do. I can find
no
other reason why the datareader is returning false straight away.


How did running the program without a while loop determine that the data
were correct?

John Saunders

"John Saunders" wrote:
"Scott Richards" <Sc***********@discussions.microsoft.com> wrote in
message
news:E7**********************************@microsof t.com...
> Sorry for the lack of information John, by the time I wrote this I had
> spent
> 5 hours researching the problem & was quite frustrated & tired.
>
> The problem is that when I run the datareader.read command the loop
> does
> not
> intiate because the command gives false

In a case like this, I would first assume that the DataReader is working
correctly. If you start with that assumption, you're left to wonder what
you
could possibly have done to make a correctly-functioning DataReader to
return false right away. For instance, are you certain that your query is
correct? If it requires parameters, are they correct? For instance, maybe
you've got a string parameter which has trailing spaces.

John Saunders


Nov 19 '05 #7
"Scott Richards" <Sc***********@discussions.microsoft.com> wrote in message
news:46**********************************@microsof t.com...
I put a watch on I(0) & got the number that I expected.
I also put a watch on the reader & the next number was in their too.
Thank you.

I suggest that you next add a couple of Read calls, not in a loop, and see
if they get the first two records.

John Saunders
"John Saunders" wrote:
"Scott Richards" <Sc***********@discussions.microsoft.com> wrote in
message
news:C5**********************************@microsof t.com...
> Hi John I have checked that the query is returning the correct data by
> running the program without the while loop. Is it possible that my
> datareader
> isn't functioning correctly? If so what would you sugest I do. I can
> find
> no
> other reason why the datareader is returning false straight away.


How did running the program without a while loop determine that the data
were correct?

John Saunders

> "John Saunders" wrote:
>
>> "Scott Richards" <Sc***********@discussions.microsoft.com> wrote in
>> message
>> news:E7**********************************@microsof t.com...
>> > Sorry for the lack of information John, by the time I wrote this I
>> > had
>> > spent
>> > 5 hours researching the problem & was quite frustrated & tired.
>> >
>> > The problem is that when I run the datareader.read command the loop
>> > does
>> > not
>> > intiate because the command gives false
>>
>> In a case like this, I would first assume that the DataReader is
>> working
>> correctly. If you start with that assumption, you're left to wonder
>> what
>> you
>> could possibly have done to make a correctly-functioning DataReader to
>> return false right away. For instance, are you certain that your query
>> is
>> correct? If it requires parameters, are they correct? For instance,
>> maybe
>> you've got a string parameter which has trailing spaces.
>>
>> John Saunders
>>
>>
>>


Nov 19 '05 #8
Thats works fine perfictly fine

Giving me the expected results

"John Saunders" wrote:
"Scott Richards" <Sc***********@discussions.microsoft.com> wrote in message
news:46**********************************@microsof t.com...
I put a watch on I(0) & got the number that I expected.
I also put a watch on the reader & the next number was in their too.


Thank you.

I suggest that you next add a couple of Read calls, not in a loop, and see
if they get the first two records.

John Saunders
"John Saunders" wrote:
"Scott Richards" <Sc***********@discussions.microsoft.com> wrote in
message
news:C5**********************************@microsof t.com...
> Hi John I have checked that the query is returning the correct data by
> running the program without the while loop. Is it possible that my
> datareader
> isn't functioning correctly? If so what would you sugest I do. I can
> find
> no
> other reason why the datareader is returning false straight away.

How did running the program without a while loop determine that the data
were correct?

John Saunders
> "John Saunders" wrote:
>
>> "Scott Richards" <Sc***********@discussions.microsoft.com> wrote in
>> message
>> news:E7**********************************@microsof t.com...
>> > Sorry for the lack of information John, by the time I wrote this I
>> > had
>> > spent
>> > 5 hours researching the problem & was quite frustrated & tired.
>> >
>> > The problem is that when I run the datareader.read command the loop
>> > does
>> > not
>> > intiate because the command gives false
>>
>> In a case like this, I would first assume that the DataReader is
>> working
>> correctly. If you start with that assumption, you're left to wonder
>> what
>> you
>> could possibly have done to make a correctly-functioning DataReader to
>> return false right away. For instance, are you certain that your query
>> is
>> correct? If it requires parameters, are they correct? For instance,
>> maybe
>> you've got a string parameter which has trailing spaces.
>>
>> John Saunders
>>
>>
>>


Nov 19 '05 #9
"Scott Richards" <Sc***********@discussions.microsoft.com> wrote in message
news:F1**********************************@microsof t.com...
Thats works fine perfictly fine

Giving me the expected results
Ok, since a couple of reads work, try a simple while loop.

John Saunders
"John Saunders" wrote:
"Scott Richards" <Sc***********@discussions.microsoft.com> wrote in
message
news:46**********************************@microsof t.com...
>I put a watch on I(0) & got the number that I expected.
> I also put a watch on the reader & the next number was in their too.


Thank you.

I suggest that you next add a couple of Read calls, not in a loop, and
see
if they get the first two records.

John Saunders
> "John Saunders" wrote:
>
>> "Scott Richards" <Sc***********@discussions.microsoft.com> wrote in
>> message
>> news:C5**********************************@microsof t.com...
>> > Hi John I have checked that the query is returning the correct data
>> > by
>> > running the program without the while loop. Is it possible that my
>> > datareader
>> > isn't functioning correctly? If so what would you sugest I do. I can
>> > find
>> > no
>> > other reason why the datareader is returning false straight away.
>>
>> How did running the program without a while loop determine that the
>> data
>> were correct?
>>
>> John Saunders
>>
>>
>> > "John Saunders" wrote:
>> >
>> >> "Scott Richards" <Sc***********@discussions.microsoft.com> wrote in
>> >> message
>> >> news:E7**********************************@microsof t.com...
>> >> > Sorry for the lack of information John, by the time I wrote this
>> >> > I
>> >> > had
>> >> > spent
>> >> > 5 hours researching the problem & was quite frustrated & tired.
>> >> >
>> >> > The problem is that when I run the datareader.read command the
>> >> > loop
>> >> > does
>> >> > not
>> >> > intiate because the command gives false
>> >>
>> >> In a case like this, I would first assume that the DataReader is
>> >> working
>> >> correctly. If you start with that assumption, you're left to wonder
>> >> what
>> >> you
>> >> could possibly have done to make a correctly-functioning DataReader
>> >> to
>> >> return false right away. For instance, are you certain that your
>> >> query
>> >> is
>> >> correct? If it requires parameters, are they correct? For instance,
>> >> maybe
>> >> you've got a string parameter which has trailing spaces.
>> >>
>> >> John Saunders
>> >>
>> >>
>> >>
>>
>>
>>


Nov 19 '05 #10
Thank you the data reader is working correctly now, could you explain why it
was not working before?

Scott Richards

"John Saunders" wrote:
"Scott Richards" <Sc***********@discussions.microsoft.com> wrote in message
news:F1**********************************@microsof t.com...
Thats works fine perfictly fine

Giving me the expected results


Ok, since a couple of reads work, try a simple while loop.

John Saunders
"John Saunders" wrote:
"Scott Richards" <Sc***********@discussions.microsoft.com> wrote in
message
news:46**********************************@microsof t.com...
>I put a watch on I(0) & got the number that I expected.
> I also put a watch on the reader & the next number was in their too.

Thank you.

I suggest that you next add a couple of Read calls, not in a loop, and
see
if they get the first two records.

John Saunders

> "John Saunders" wrote:
>
>> "Scott Richards" <Sc***********@discussions.microsoft.com> wrote in
>> message
>> news:C5**********************************@microsof t.com...
>> > Hi John I have checked that the query is returning the correct data
>> > by
>> > running the program without the while loop. Is it possible that my
>> > datareader
>> > isn't functioning correctly? If so what would you sugest I do. I can
>> > find
>> > no
>> > other reason why the datareader is returning false straight away.
>>
>> How did running the program without a while loop determine that the
>> data
>> were correct?
>>
>> John Saunders
>>
>>
>> > "John Saunders" wrote:
>> >
>> >> "Scott Richards" <Sc***********@discussions.microsoft.com> wrote in
>> >> message
>> >> news:E7**********************************@microsof t.com...
>> >> > Sorry for the lack of information John, by the time I wrote this
>> >> > I
>> >> > had
>> >> > spent
>> >> > 5 hours researching the problem & was quite frustrated & tired.
>> >> >
>> >> > The problem is that when I run the datareader.read command the
>> >> > loop
>> >> > does
>> >> > not
>> >> > intiate because the command gives false
>> >>
>> >> In a case like this, I would first assume that the DataReader is
>> >> working
>> >> correctly. If you start with that assumption, you're left to wonder
>> >> what
>> >> you
>> >> could possibly have done to make a correctly-functioning DataReader
>> >> to
>> >> return false right away. For instance, are you certain that your
>> >> query
>> >> is
>> >> correct? If it requires parameters, are they correct? For instance,
>> >> maybe
>> >> you've got a string parameter which has trailing spaces.
>> >>
>> >> John Saunders
>> >>
>> >>
>> >>
>>
>>
>>


Nov 19 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Yasutaka Ito | last post by:
Hi, My friend had a little confusion about the working of DataReader after reading an article from MSDN. Following is a message from him... <!-- Message starts --> I was going thru DataReader...
2
by: Wayne Wengert | last post by:
I am trying to learn to use VS NET and codebehind for asp.net apps and I've run into a problem trying to use a datareader. I created a new webform and inserted and configured a sqlconnection and...
4
by: Maziar Aflatoun | last post by:
Hi everyone, I am working on the 'Delete' section of my program. What I need to do is query my database and for every ID that it finds I want to remove a file+ID.jpg from my file folder and...
4
by: Shapper | last post by:
Hello, I have this code to bind a DataGrid to a DataReader when page loads: Sub Page_Load(Sender As Object, e As EventArgs) dgContent.DataSource = drContent dgContent.DataBind() End Sub ...
4
by: Shapper | last post by:
Hello, I have created a datareader function in a asp.net/vb web site. The datareader returns only one record with 2 fields: and In the same aspx.vb I want to use this values as follows:...
3
by: Tim::.. | last post by:
Can anyone tell me how to achieve the following... I want to convert data from a DataReader into a DataTable... I was told this should do it but it doesn't seem to work! Dim Myconn As New...
4
by: hazz | last post by:
The data access layer below returns, well, a mess as you can see on the last line of this posting. What is the best way to return customer objects via a datareader from the data layer into my view...
3
by: tshad | last post by:
I am using VS 2003 and trying to build a standalone application. I have been writing all my asp.net work using DW and am just now trying to build a application that will read some of the tables I...
10
by: jimmy | last post by:
Hi again, sorry for posting two questions so close together but im working on a school project which is due in soon and running into some difficulties implementing the database parts. I have the...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.