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

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 4471

"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
by: Ricola ! | last post by:
Why do I say: SqlDataReader dr; instead of SqlDataReader dr = new SqlDataReader();
7
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
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
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
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
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
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
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
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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
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...
0
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
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...

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.