473,386 Members | 1,708 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,386 software developers and data experts.

While objdr.read() problem

Dim objdr As Data.OracleClient.OracleDataReader = Nothing
Dim objcnn As Data.OracleClient.OracleConnection = Nothing
Dim objcom As Data.OracleClient.OracleCommand
objcom = New
Data.OracleClient.OracleCommand(BuildSQL("Notes", id), objcnn)
objdr = objcom.ExecuteReader
objdr.Read()
If objdr.HasRows Then 'Everything OK so far
While objdr.Read() 'Jumps straight to End If here
'do something, it never gets here
End While
Else
'do something else
End If

I am using the code above, it passes through "If objdr.HasRows Then"
so obviously has rows, however as soon as it gets to the next line it
jumps to "End If"

I also tried it using "Do while objdr.read() - Loop" and got the same
behavour, I don't understand why it won't loop through the results,
there is definately at least one row, but it needs to be able to
handle several rows, hence the loop

Mar 20 '07 #1
7 2385
What makes you so certain it has any rows?

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
Networking Components, Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net

"Problematic coder" <gn******@gmail.comwrote in message
news:11**********************@y66g2000hsf.googlegr oups.com...
Dim objdr As Data.OracleClient.OracleDataReader = Nothing
Dim objcnn As Data.OracleClient.OracleConnection = Nothing
Dim objcom As Data.OracleClient.OracleCommand
objcom = New
Data.OracleClient.OracleCommand(BuildSQL("Notes", id), objcnn)
objdr = objcom.ExecuteReader
objdr.Read()
If objdr.HasRows Then 'Everything OK so far
While objdr.Read() 'Jumps straight to End If here
'do something, it never gets here
End While
Else
'do something else
End If

I am using the code above, it passes through "If objdr.HasRows Then"
so obviously has rows, however as soon as it gets to the next line it
jumps to "End If"

I also tried it using "Do while objdr.read() - Loop" and got the same
behavour, I don't understand why it won't loop through the results,
there is definately at least one row, but it needs to be able to
handle several rows, hence the loop

Mar 20 '07 #2
Problematic coder wrote:
Dim objdr As Data.OracleClient.OracleDataReader = Nothing
Dim objcnn As Data.OracleClient.OracleConnection = Nothing
Dim objcom As Data.OracleClient.OracleCommand
objcom = New
Data.OracleClient.OracleCommand(BuildSQL("Notes", id), objcnn)
objdr = objcom.ExecuteReader
objdr.Read()
If objdr.HasRows Then 'Everything OK so far
While objdr.Read() 'Jumps straight to End If here
'do something, it never gets here
End While
Else
'do something else
End If

I am using the code above, it passes through "If objdr.HasRows Then"
so obviously has rows, however as soon as it gets to the next line it
jumps to "End If"

I also tried it using "Do while objdr.read() - Loop" and got the same
behavour, I don't understand why it won't loop through the results,
there is definately at least one row, but it needs to be able to
handle several rows, hence the loop
In this case it has one row, and you skip over that row.

THe first call to Read makes the first row accessible throught the
reader, but you don't do anything with that row, instead you go to the
loop where you start by skipping to the next row and do something with
that. That means that you always skip the first row, and if there is
only one row, you don't do anything more.

Remove the first call to Read.

--
Göran Andersson
_____
http://www.guffa.com
Mar 20 '07 #3
You read the row before testing HasRows and entering the loop. Removing this
extra read should solve the problem....

---
Patrice

"Problematic coder" <gn******@gmail.coma écrit dans le message de news:
11**********************@y66g2000hsf.googlegroups. com...
Dim objdr As Data.OracleClient.OracleDataReader = Nothing
Dim objcnn As Data.OracleClient.OracleConnection = Nothing
Dim objcom As Data.OracleClient.OracleCommand
objcom = New
Data.OracleClient.OracleCommand(BuildSQL("Notes", id), objcnn)
objdr = objcom.ExecuteReader
objdr.Read()
If objdr.HasRows Then 'Everything OK so far
While objdr.Read() 'Jumps straight to End If here
'do something, it never gets here
End While
Else
'do something else
End If

I am using the code above, it passes through "If objdr.HasRows Then"
so obviously has rows, however as soon as it gets to the next line it
jumps to "End If"

I also tried it using "Do while objdr.read() - Loop" and got the same
behavour, I don't understand why it won't loop through the results,
there is definately at least one row, but it needs to be able to
handle several rows, hence the loop

Mar 20 '07 #4
On Mar 20, 10:26 am, "Kevin Spencer" <unclechut...@nothinks.com>
wrote:
What makes you so certain it has any rows?

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
Networking Components, Controls, much more.
DSI PrintManager, Miradyne Component Libraries:http://www.miradyne.net

"Problematic coder" <gnews...@gmail.comwrote in message

news:11**********************@y66g2000hsf.googlegr oups.com...
Dim objdr As Data.OracleClient.OracleDataReader = Nothing
Dim objcnn As Data.OracleClient.OracleConnection = Nothing
Dim objcom As Data.OracleClient.OracleCommand
objcom = New
Data.OracleClient.OracleCommand(BuildSQL("Notes", id), objcnn)
objdr = objcom.ExecuteReader
objdr.Read()
If objdr.HasRows Then 'Everything OK so far
While objdr.Read() 'Jumps straight to End If here
'do something, it never gets here
End While
Else
'do something else
End If
I am using the code above, it passes through "If objdr.HasRows Then"
so obviously has rows, however as soon as it gets to the next line it
jumps to "End If"
I also tried it using "Do while objdr.read() - Loop" and got the same
behavour, I don't understand why it won't loop through the results,
there is definately at least one row, but it needs to be able to
handle several rows, hence the loop- Hide quoted text -

- Show quoted text -
Two reasons, one I confirmed it with a sql query and two the fact that
it doesn't go to "else"

Mar 20 '07 #5
On Mar 20, 10:48 am, Göran Andersson <g...@guffa.comwrote:
Problematic coder wrote:
Dim objdr As Data.OracleClient.OracleDataReader = Nothing
Dim objcnn As Data.OracleClient.OracleConnection = Nothing
Dim objcom As Data.OracleClient.OracleCommand
objcom = New
Data.OracleClient.OracleCommand(BuildSQL("Notes", id), objcnn)
objdr = objcom.ExecuteReader
objdr.Read()
If objdr.HasRows Then 'Everything OK so far
While objdr.Read() 'Jumps straight to End If here
'do something, it never gets here
End While
Else
'do something else
End If
I am using the code above, it passes through "If objdr.HasRows Then"
so obviously has rows, however as soon as it gets to the next line it
jumps to "End If"
I also tried it using "Do while objdr.read() - Loop" and got the same
behavour, I don't understand why it won't loop through the results,
there is definately at least one row, but it needs to be able to
handle several rows, hence the loop

In this case it has one row, and you skip over that row.

THe first call to Read makes the first row accessible throught the
reader, but you don't do anything with that row, instead you go to the
loop where you start by skipping to the next row and do something with
that. That means that you always skip the first row, and if there is
only one row, you don't do anything more.

Remove the first call to Read.

--
Göran Andersson
_____http://www.guffa.com- Hide quoted text -

- Show quoted text -
I see what you are saying but that doesn't seem to be the case, to
test this I comented out the first call and was left with this:

objdr.Read()
While objdr.Read() ' It jumped from here to the
next line of code
'do something, it never gets here
End While
'Next line of code

You are on the right lines, the next test I did was add another
record, and the loop now works, however only the second record shows
up, ie it only loops once, if there is only one record it doesn't loop
at all, so it is ignoring the first record.

Here is the code inside the loop:

textBox.text = textBox.text & objdr.item("column_name") & "<br>"

So, any ideas how to make it also include the first line?

Thanks for feedback already given

Mar 20 '07 #6
On Mar 20, 11:18 am, "Problematic coder" <gnews...@gmail.comwrote:
On Mar 20, 10:48 am, Göran Andersson <g...@guffa.comwrote:


Problematic coder wrote:
Dim objdr As Data.OracleClient.OracleDataReader = Nothing
Dim objcnn As Data.OracleClient.OracleConnection = Nothing
Dim objcom As Data.OracleClient.OracleCommand
objcom = New
Data.OracleClient.OracleCommand(BuildSQL("Notes", id), objcnn)
objdr = objcom.ExecuteReader
objdr.Read()
If objdr.HasRows Then 'Everything OK so far
While objdr.Read() 'Jumps straight to End If here
'do something, it never gets here
End While
Else
'do something else
End If
I am using the code above, it passes through "If objdr.HasRows Then"
so obviously has rows, however as soon as it gets to the next line it
jumps to "End If"
I also tried it using "Do while objdr.read() - Loop" and got the same
behavour, I don't understand why it won't loop through the results,
there is definately at least one row, but it needs to be able to
handle several rows, hence the loop
In this case it has one row, and you skip over that row.
THe first call to Read makes the first row accessible throught the
reader, but you don't do anything with that row, instead you go to the
loop where you start by skipping to the next row and do something with
that. That means that you always skip the first row, and if there is
only one row, you don't do anything more.
Remove the first call to Read.
--
Göran Andersson
_____http://www.guffa.com-Hide quoted text -
- Show quoted text -

I see what you are saying but that doesn't seem to be the case, to
test this I comented out the first call and was left with this:

objdr.Read()
While objdr.Read() ' It jumped from here to the
next line of code
'do something, it never gets here
End While
'Next line of code

You are on the right lines, the next test I did was add another
record, and the loop now works, however only the second record shows
up, ie it only loops once, if there is only one record it doesn't loop
at all, so it is ignoring the first record.

Here is the code inside the loop:

textBox.text = textBox.text & objdr.item("column_name") & "<br>"

So, any ideas how to make it also include the first line?

Thanks for feedback already given- Hide quoted text -

- Show quoted text -
Got it, the answer was given above and I misread it - the additional
objdr.read() was the problem, I had assumed I had to do that before
testing for hasrows - apparently not - deleted that and all is good -
thanks again

Mar 20 '07 #7
Glad you got it solved!

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
Networking Components, Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net

"Problematic coder" <gn******@gmail.comwrote in message
news:11**********************@l77g2000hsb.googlegr oups.com...
On Mar 20, 10:26 am, "Kevin Spencer" <unclechut...@nothinks.com>
wrote:
>What makes you so certain it has any rows?

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
Networking Components, Controls, much more.
DSI PrintManager, Miradyne Component Libraries:http://www.miradyne.net

"Problematic coder" <gnews...@gmail.comwrote in message

news:11**********************@y66g2000hsf.googleg roups.com...
Dim objdr As Data.OracleClient.OracleDataReader = Nothing
Dim objcnn As Data.OracleClient.OracleConnection = Nothing
Dim objcom As Data.OracleClient.OracleCommand
objcom = New
Data.OracleClient.OracleCommand(BuildSQL("Notes", id), objcnn)
objdr = objcom.ExecuteReader
objdr.Read()
If objdr.HasRows Then 'Everything OK so far
While objdr.Read() 'Jumps straight to End If here
'do something, it never gets here
End While
Else
'do something else
End If
I am using the code above, it passes through "If objdr.HasRows Then"
so obviously has rows, however as soon as it gets to the next line it
jumps to "End If"
I also tried it using "Do while objdr.read() - Loop" and got the same
behavour, I don't understand why it won't loop through the results,
there is definately at least one row, but it needs to be able to
handle several rows, hence the loop- Hide quoted text -

- Show quoted text -

Two reasons, one I confirmed it with a sql query and two the fact that
it doesn't go to "else"

Mar 21 '07 #8

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

Similar topics

4
by: BigAl | last post by:
I am using the following code in a servlet to send data back to a J2ME application:
2
by: Jonathan | last post by:
Hi I'm doing a project for school and wrote an applet that makes a socket connection to a server (smae host as webserver) that was setup for this project. In the applet there are 3 buttons and by...
3
by: CanyonJ | last post by:
I've been running into a frustrating problem for a while now. I use image.FromStream to open a tif, then perform some drawstring methods, and then save the file again. The tiffs are in 1 bit per...
75
by: Greg McIntyre | last post by:
I have a Python snippet: f = open("blah.txt", "r") while True: c = f.read(1) if c == '': break # EOF # ... work on c Is some way to make this code more compact and simple? It's a bit...
8
by: dbuser | last post by:
Hi, I need help on a problem, as described below. I am reading a file "input.txt"which has data like this: abc def gh izk lmnopq rst uvwxyz I am using fstream object to read the file and...
147
by: Michael B Allen | last post by:
Should there be any preference between the following logically equivalent statements? while (1) { vs. for ( ;; ) { I suspect the answer is "no" but I'd like to know what the consensus is
3
by: Anup Daware | last post by:
Hi Group, I am facing a strange problem here: I am trying to read xml response from a servlet using XmlTextWriter. I am able to read the read half of the xml and suddenly an exception:...
0
by: VeeraLakshmi | last post by:
I am doing a project for internet control using Java,PHP and MySql.All sites should go through the proxy server only.We are giving access rights as allow or deny to the sites.If we type the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.