473,486 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

SQL Reader problem

Hi,
I have the following code.

Dim RD As System.Data.SqlClient.SqlDataReader
Try 'Try2
OpenConnection()
RD = cmdSQL.ExecuteReader
While RD.Read = True
UserIDSQL = CInt(RD.Item("UserID"))
EncUserNameSQL = CStr(RD.Item("UserName"))
EncPasswordSQL = CStr(RD.Item("Password"))
PassExpirationDateSQL =
CDate(RD.Item("PasswordExpirationDate"))
IPAddressSQL = CStr(RD.Item("IPAddress"))
AllowOnlyThisIPAddress =
CBool(RD.Item("AllowOnlyThisIPAddress"))
AllowLoginFromWeb =
CBool(RD.Item("AllowLoginFromWeb"))
End While
Catch ex As Exception
msgbox(ex.Message)
Finally
CloseConnection()
End Try

I get some strange behavior.
When Run, it does not set values to variables in 'While' block.
When Debug it goes to line 'While RD.Read' and the next line executed is
'Finally'
Why?

TIA
Nov 21 '05 #1
6 941
"Nikolay Petrov" <jo**************@mail.bg> schrieb:
Dim RD As System.Data.SqlClient.SqlDataReader
Try 'Try2
OpenConnection()
RD = cmdSQL.ExecuteReader
While RD.Read = True
UserIDSQL = CInt(RD.Item("UserID"))
EncUserNameSQL = CStr(RD.Item("UserName"))
EncPasswordSQL = CStr(RD.Item("Password"))
PassExpirationDateSQL =
CDate(RD.Item("PasswordExpirationDate"))
IPAddressSQL = CStr(RD.Item("IPAddress"))
AllowOnlyThisIPAddress =
CBool(RD.Item("AllowOnlyThisIPAddress"))
AllowLoginFromWeb =
CBool(RD.Item("AllowLoginFromWeb"))
End While
Catch ex As Exception
msgbox(ex.Message)
Finally
CloseConnection()
End Try

I get some strange behavior.
When Run, it does not set values to variables in 'While' block.
When Debug it goes to line 'While RD.Read' and the next line executed is
'Finally'
Why?


Maybe the 'Read' method returns 'False', then the 'While' loop is skipped
and the 'Finally' part is executed. 'Finally' will be executed even if no
exception was thrown.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #2
Any idea why SQLDataReader returns false
I am using a stored procedure and I am sure it returns data.

Nov 21 '05 #3
Nicolay,

Than why not in your finallyblock
Messagebox.show(EncUserNameSQL)

Or something like that.

It is a little thing to test, it will not be the first time that people are
"sure".

Cor
"Nikolay Petrov" <jo**************@mail.bg>
Any idea why SQLDataReader returns false
I am using a stored procedure and I am sure it returns data.

Nov 21 '05 #4
The
While RD.Read is FALSE at the first loop
it nevers assign anything to variables

when run in server explorer the stored procedure retruns data.

how can i see the returned data from SQL while debuging?


"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Nicolay,

Than why not in your finallyblock
Messagebox.show(EncUserNameSQL)

Or something like that.

It is a little thing to test, it will not be the first time that people
are "sure".

Cor
"Nikolay Petrov" <jo**************@mail.bg>
Any idea why SQLDataReader returns false
I am using a stored procedure and I am sure it returns data.


Nov 21 '05 #5
As I wrote
Than why not in your finallyblock
Messagebox.show(EncUserNameSQL)
When it is a webpage you can create a label on that and set than this
varialble too that.

You can of course as well debug it, your stored procedure is only a
description what has to be readed.

Cor
While RD.Read is FALSE at the first loop
it nevers assign anything to variables

when run in server explorer the stored procedure retruns data.

how can i see the returned data from SQL while debuging?


"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Nicolay,

Than why not in your finallyblock
Messagebox.show(EncUserNameSQL)

Or something like that.

It is a little thing to test, it will not be the first time that people
are "sure".

Cor
"Nikolay Petrov" <jo**************@mail.bg>
Any idea why SQLDataReader returns false
I am using a stored procedure and I am sure it returns data.



Nov 21 '05 #6
On Fri, 3 Dec 2004 15:35:14 +0200, Nikolay Petrov wrote:

how can i see the returned data from SQL while debuging?


If you run SQL Profiler, you can see what the query sent to SQL Server and
verify if it is correct.

--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
Nov 21 '05 #7

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

Similar topics

6
519
by: | last post by:
I am rewriting a C++ application in C#. This file has a combination of Text and Binary data. I used CFile before to read the text. If I hit a certain string that denotes the following data is...
1
4202
by: Craig Beuker | last post by:
Hello, I am experimenting with this XmlValidatingReader and have a question about how it is working (or not working as would be the case) The sample documents and code are included at the end...
1
1891
by: Anand | last post by:
I just implemented a program to solve reader writter prob. Wenever I run the program it seems to go into S+ state and it waits there I dont know why. When i attach gdb to one of the childs and step...
5
17682
by: Drew Yallop | last post by:
I read an XML file with a stream reader in VB.Net. When I look at the stream reader output in debug mode (by passing cursor over the stream reader object)the format is a perfect replica of the...
3
1504
by: Craig Lister | last post by:
Newbie alert! I am trying to get data from my mySQL database... With some help, I have got this far, but there is an exception in data.dll (??) on the : "OleDbDataReader Reader =...
2
5037
by: Patrick Olurotimi Ige | last post by:
Why do i get "Invalid attempt to FieldCount when reader is closed" Is the problem the way the datareader reads data as opposed to a dataset? When trying to compile this code:- Dim reader As...
4
1720
by: Ram | last post by:
I am using ADO.Net data reader to retrieve data from main frame. I am getting timestamp which is 26 (yyyy-mm-dd hh- mm-ss.123456) bytes as sqltimestamp data type. I am using data reader to...
12
11134
by: Jerry Camel | last post by:
Not sure if this is a good place to post this... I'm writing and ASP.net app using vb .net. I need to interact with a credit card reader. I have one that sits inline with the keyboard. Works...
3
1567
by: John | last post by:
Hi I am getting the System.IndexOutOfRangeException was unhandled error on the last line of below code; Cmd = New OleDb.OleDbCommand("SELECT FROM ", LocalConn) Reader = Cmd.ExecuteReader()...
3
2685
by: =?Utf-8?B?cm9kY2hhcg==?= | last post by:
hey all, how do you resolve this problem? i have a public procedure in my DataAccessLayer that gets a SqlDataReader how do i close the reader from inside the DataAccessLayer if I'm returning...
0
7099
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
6964
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...
1
6842
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7319
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
4559
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1378
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
598
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
262
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.