473,657 Members | 2,451 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Two SqlDataReader problem

I got two sub method to check some history record, Now, I found that there
is some problem in Sub2() .
I think the problem is about the myReader. However, I got no idea to solve
it . As Sub2() will be used by another function. I cannot combine them ,
Please help. Thanks a lot.
private Sub Sub1()
Dim cmd As New SqlClient.SqlCo mmand("select invno from
arinvinfo , _conn)
Dim myReader As SqlDataReader
myReader = cmd.ExecuteRead er
Do While myReader.Read
Me.sub2(myReade r.item(("invno" )
loop
End sub
private sub2()
Dim cmd As New SqlClient.SqlCo mmand("select invno from
history , _conn)
Dim myReader As SqlDataReader
myReader = cmd.ExecuteRead er
Do While myReader.Read
'Check History
loop
end sub
Nov 21 '05 #1
4 3231
It looks like you're calling sub2 with parameters, but sub2 doesn't take any
parameters.

"Agnes" <ag***@dynamict ech.com.hk> wrote in message
news:uc******** ******@tk2msftn gp13.phx.gbl...
I got two sub method to check some history record, Now, I found that there
is some problem in Sub2() .
I think the problem is about the myReader. However, I got no idea to solve
it . As Sub2() will be used by another function. I cannot combine them ,
Please help. Thanks a lot.
private Sub Sub1()
Dim cmd As New SqlClient.SqlCo mmand("select invno from
arinvinfo , _conn)
Dim myReader As SqlDataReader
myReader = cmd.ExecuteRead er
Do While myReader.Read
Me.sub2(myReade r.item(("invno" )
loop
End sub
private sub2()
Dim cmd As New SqlClient.SqlCo mmand("select invno from
history , _conn)
Dim myReader As SqlDataReader
myReader = cmd.ExecuteRead er
Do While myReader.Read
'Check History
loop
end sub

Nov 21 '05 #2
Agnes,

You can't have 2 datareaders open on the same connection. Sub2 will need its
own connection object.

Kerry Moorman
"Agnes" wrote:
I got two sub method to check some history record, Now, I found that there
is some problem in Sub2() .
I think the problem is about the myReader. However, I got no idea to solve
it . As Sub2() will be used by another function. I cannot combine them ,
Please help. Thanks a lot.
private Sub Sub1()
Dim cmd As New SqlClient.SqlCo mmand("select invno from
arinvinfo , _conn)
Dim myReader As SqlDataReader
myReader = cmd.ExecuteRead er
Do While myReader.Read
Me.sub2(myReade r.item(("invno" )
loop
End sub
private sub2()
Dim cmd As New SqlClient.SqlCo mmand("select invno from
history , _conn)
Dim myReader As SqlDataReader
myReader = cmd.ExecuteRead er
Do While myReader.Read
'Check History
loop
end sub

Nov 21 '05 #3
So , Any solution ?? Please help

"Kerry Moorman" <Ke**********@d iscussions.micr osoft.com> ¼¶¼g©ó¶l¥ó·s»D: 6F************* *************** ******@microsof t.com...
Agnes,

You can't have 2 datareaders open on the same connection. Sub2 will need
its
own connection object.

Kerry Moorman
"Agnes" wrote:
I got two sub method to check some history record, Now, I found that
there
is some problem in Sub2() .
I think the problem is about the myReader. However, I got no idea to
solve
it . As Sub2() will be used by another function. I cannot combine them ,
Please help. Thanks a lot.
private Sub Sub1()
Dim cmd As New SqlClient.SqlCo mmand("select invno from
arinvinfo , _conn)
Dim myReader As SqlDataReader
myReader = cmd.ExecuteRead er
Do While myReader.Read
Me.sub2(myReade r.item(("invno" )
loop
End sub
private sub2()
Dim cmd As New SqlClient.SqlCo mmand("select invno from
history , _conn)
Dim myReader As SqlDataReader
myReader = cmd.ExecuteRead er
Do While myReader.Read
'Check History
loop
end sub

Nov 21 '05 #4
Agnes,

We see no open and close statements.

Not unlikely the only problem

Cor

"Agnes" <ag***@dynamict ech.com.hk> schreef in bericht
news:u%******** ********@TK2MSF TNGP14.phx.gbl. ..
So , Any solution ?? Please help

"Kerry Moorman" <Ke**********@d iscussions.micr osoft.com>
¼¶¼g©ó¶l¥ó·s»D: 6F************* *************** ******@microsof t.com...
Agnes,

You can't have 2 datareaders open on the same connection. Sub2 will need
its
own connection object.

Kerry Moorman
"Agnes" wrote:
I got two sub method to check some history record, Now, I found that
there
is some problem in Sub2() .
I think the problem is about the myReader. However, I got no idea to
solve
it . As Sub2() will be used by another function. I cannot combine them ,
Please help. Thanks a lot.
private Sub Sub1()
Dim cmd As New SqlClient.SqlCo mmand("select invno from
arinvinfo , _conn)
Dim myReader As SqlDataReader
myReader = cmd.ExecuteRead er
Do While myReader.Read
Me.sub2(myReade r.item(("invno" )
loop
End sub
private sub2()
Dim cmd As New SqlClient.SqlCo mmand("select invno from
history , _conn)
Dim myReader As SqlDataReader
myReader = cmd.ExecuteRead er
Do While myReader.Read
'Check History
loop
end sub


Nov 21 '05 #5

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

Similar topics

3
536
by: Ricola ! | last post by:
Why do I say: SqlDataReader dr; instead of SqlDataReader dr = new SqlDataReader();
2
7386
by: Matthias S. | last post by:
Hi, I've written a simple app which should just fetch some data from a database and render the results into a ListView. In order to not freeze the GUI, I'm using a BackgroundWorker. The arguments for the RunWorkerAsync are the Query to be executed and the Connectionstring. As a result I hoped I could return a SqlDataReader. The problem is, if I create the SqlDataReader within the
7
2358
by: Franck Diastein | last post by:
Hi, when I call ExportData I have this error: Invalid attempt to Read when reader is closed. Telling me that there's a problem with this line: while(_dataR.Read()){ Code: ************************************************* public void Export2CSV(){
3
5880
by: Neil Guyette | last post by:
Hello, Everyone, I'm trying to find information on how to populate a combo box using a SqlDataReader. I want to be able to set the value of the combo's value property different then the combo's text property (what the user will see). Is this possible with a SqlDataReader? Thanks
1
3254
by: Arvind P Rangan | last post by:
Hi All, How do you get all the values of a sqldatareader if it contains multiple resultset. Using sqldatareader.nextresult and sqldatareader.read e.g. While sqldatareader.read ' If not sqldatareader then sqldatareader.nextresult
8
2070
by: bidllc | last post by:
I have a funtion that works fine and dandy when called from anywhere in my app. It will NOT work when called from inside the class in which it resides. This is the function I'm calling: "getProductByID(productID)" from inside another method in the same class. See below. This line throws a null ref exception: While dr.Read() Thanks for any insight!
4
2359
by: mimi | last post by:
Hi Please help me out, I can't find a way to close a sqldatareader when error occur at statement cmd.ExecuteReader(). I can't close it in catch because it is local in try scope and I can't declare it outside try scope either since we have to call cmd.executeReader to create sqldatareader public string GetLogs(int logID) {
7
1708
by: Web learner | last post by:
I am trying to create a method GetDataFor(string column) becaues I have to repeat the same statements for several columns but I get an error as follows: The name 'dr' does not exist in the current context It seems the dr -the instance of sqlDataReader - is not becoming available to the method. How to make it available? This seems trivial and newbie problem related to OOP, but I am confused. Could you pl. look at the code or point me to...
3
1306
by: yogarajan | last post by:
hi i am using two sqldatareader. that gives error My code start here SqlConnection conn = new SqlConnection("Data Source=**********;Initial Catalog=****; User Id=****; Password=******"); conn.Open(); //collect all employee// SqlCommand cmd = new SqlCommand("Select * from tblhrims_employeedetail where nvrresigned='no'",conn); SqlDataReader sqldr = cmd.ExecuteReader();
0
8392
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8305
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8823
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8503
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8603
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7320
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5632
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4301
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1604
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.