473,508 Members | 2,303 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SqlDataReader

I am currently writing my first application in VB.Net and have come accross
the following problem, my code is as follows

'Alllocate memory for class objects
m_oBusiness = New Validation()
m_oGetMethods = New RetrieveData()
m_oDataReader = New SqlDataReader()

lnResult = IIf(m_oGetMethods.GetList("Users", m_oDataReader) = 0, True,
False)
If lnResult = 0 Then
With m_oDataReader
'Run through table adding club names to list box for selection
Do Until .Read = True
'need to subtract 1 from clubkey as index of combo starts at 0
and database starts at 1
cmbClubName.Items.Insert(.Item("Club_Key") - 1,
Trim(.Item("Club_Name")))
Loop
End With
End if
when i do the line "m_oDataReader = New SqlDataReader()" to allocate the
memory the folloing error appears on building
C:\Documents and Settings\Stuart\My Documents\Visual Studio
Projects\HCapCalc\HCalc_UI\frmLogin.vb(261):
'System.Data.SqlClient.SqlDataReader.Private Overloads Sub New(command As
System.Data.SqlClient.SqlCommand)' is not accessible in this context because
it is 'Private'.

I wondered if anyone had come accross this before

Any help would be appreciated

Best Wishes

Stuart Ferguson
Nov 20 '05 #1
2 4476

"Stuart Ferguson" <st****@ferguson1980.fsnet.co.uk> wrote in message
news:bu**********@newsg3.svr.pol.co.uk...
I am currently writing my first application in VB.Net and have come accross the following problem, my code is as follows

'Alllocate memory for class objects
m_oBusiness = New Validation()
m_oGetMethods = New RetrieveData()
m_oDataReader = New SqlDataReader()


You shoudn't be trying to "Allocate memory" for objects at the top of your
method. You can't construct a SqlDataReader yet.
First you need a SQLConnection, and a SqlCommand.
Once you have a SqlCommand, then get a reader with
SqlCommand.ExecuteReader().

Also
m_oDataReader

The DataReader should be a local, not a module or instance-level variable.
And in .NET everyting is an object, so you can leave off with the "o"
prefix.

Something like"

dim con = new SqlConnection("[some connection string]")
con.open()
try
dim cmd as new SqlCommand("Select * from MyTable",con)
dim dr as SqlDataReader = cmd.ExecuteNonQuery()
do while dr.read
. . .
loop
finally
con.close()
end try

David
Nov 20 '05 #2
All the SQL Connection and Command stuff is being handled in a dll
I am just attempting to pass the DataReader in by reference

Stuart

"David Browne" <davidbaxterbrowne no potted me**@hotmail.com> wrote in
message news:e#**************@TK2MSFTNGP12.phx.gbl...

"Stuart Ferguson" <st****@ferguson1980.fsnet.co.uk> wrote in message
news:bu**********@newsg3.svr.pol.co.uk...
I am currently writing my first application in VB.Net and have come

accross
the following problem, my code is as follows

'Alllocate memory for class objects
m_oBusiness = New Validation()
m_oGetMethods = New RetrieveData()
m_oDataReader = New SqlDataReader()


You shoudn't be trying to "Allocate memory" for objects at the top of your
method. You can't construct a SqlDataReader yet.
First you need a SQLConnection, and a SqlCommand.
Once you have a SqlCommand, then get a reader with
SqlCommand.ExecuteReader().

Also
m_oDataReader

The DataReader should be a local, not a module or instance-level variable.
And in .NET everyting is an object, so you can leave off with the "o"
prefix.

Something like"

dim con = new SqlConnection("[some connection string]")
con.open()
try
dim cmd as new SqlCommand("Select * from MyTable",con)
dim dr as SqlDataReader = cmd.ExecuteNonQuery()
do while dr.read
. . .
loop
finally
con.close()
end try

David

Nov 20 '05 #3

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();
7
2344
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:...
3
5866
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...
1
3245
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...
4
2878
by: Michael Carr | last post by:
I have a function that populates a class with values from a database. I'd like to pass into the function either a SqlDataReader or a DataRow, depending on which mechanism I'm using to retrieve data...
1
1420
by: me | last post by:
Why is SqlDataReader not present in visual studios Toolbox->Data where I find components like DataSet? Most examples in books and in vs.net are based on datasets but using disconnected tables seems...
8
2059
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:...
4
2356
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...
7
1698
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...
0
7225
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
7123
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
7324
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
7382
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...
1
7042
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
5627
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
3193
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3181
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1556
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 ...

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.