By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,041 Members | 958 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,041 IT Pros & Developers. It's quick & easy.

SqlDataReader

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a

"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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.