473,320 Members | 2,124 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,320 software developers and data experts.

Passing Datareader as ref parameter in function

I passed the Datareader as the referenced parameter, but it showing the following error.

Value of type '1-dimensional array of System.Data.SqlClient.SqlDataReader' cannot be converted to 'System.Data.SqlClient.SqlDataReader'.

My Code is as below

Function

Public Function getAllPostalCode(ByRef rsPostalCode As SqlClient.SqlDataReader) As Boolean

Dim oCon As SqlClient.SqlConnection
Dim oCommand As SqlClient.SqlCommand

Dim SQL As String

Try
oCon = mdConnection.GetConnection

SQL = "SELECT * FROM Postal_Code"

oCommand = New SqlClient.SqlCommand(SQL, oCon)
rsPostalCode = oCommand.ExecuteReader()

getAllPostalCode = True
Catch
getAllPostalCode = False
MsgBox(Err.Description)
End Try

oCon.Close()
End Function


Calling Part
Dim oPostalCode As New clsPostalCode()
Dim rsPostalCode As SqlClient.SqlDataReader()

If Not oPostalCode.getAllPostalCode(rsPostalCode) Then Exit Sub
Aug 27 '07 #1
2 3584
phvfl
173 Expert 100+
Hi,

In your declaration you are declaring rsPostalCode as an array of datareaders. Change the declaration to:
Expand|Select|Wrap|Line Numbers
  1. Dim rsPostalCode As SqlClient.SqlDataReader
  2.  
Aug 27 '07 #2
Thanks !! It Works For Me.
Aug 27 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: blue | last post by:
We often get connection pooling errors saying that there are no available connections in the pool. I think the problem is that we are passing around open readers all over the place. I am...
2
by: Martin Raychev | last post by:
Hi all, I have the following problem: I have a private method that returns a SqlDataReader. For this to work I have not to close the DB connection in the above method. I do this only to
4
by: Shapper | last post by:
Hello, I have this code to bind a DataGrid to a DataReader when page loads: Sub Page_Load(Sender As Object, e As EventArgs) dgContent.DataSource = drContent dgContent.DataBind() End Sub ...
3
by: Miguel | last post by:
Hi, I'm new to .NET and am using VB .NET as I am from a VB background. I am having difficulty understanding the way .NET handles, passes and uses objects. I have had a look at the Micrsoft Data...
11
by: John Pass | last post by:
Hi, In the attached example, I do understand that the references are not changed if an array is passed by Val. What I do not understand is the result of line 99 (If one can find this by line...
5
by: jjmraz | last post by:
Hi, I have a situation where in a dll a SqlDataReader is created on a function call but is never closed. The datareader gets passed back to the asp.net page calling it. How should I close the...
1
by: John Wright | last post by:
I want to create a generic data layer that uses Oracle as the back end. By generic, I just want a couple of procedures. All access will be done with stored procs, and I want one that returns a...
12
by: dave_dp | last post by:
Hi, I have just started learning C++ language.. I've read much even tried to understand the way standard says but still can't get the grasp of that concept. When parameters are passed/returned...
2
by: bcshaw | last post by:
Hey all I have a vb.net/asp.net dynamic website connected to an access database using a oledb connection. I use a datareader to retrieve the results of a query and iterate through the results using...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.