473,765 Members | 2,065 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing Datareader as ref parameter in function

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

Value of type '1-dimensional array of System.Data.Sql Client.SqlDataR eader' cannot be converted to 'System.Data.Sq lClient.SqlData Reader'.

My Code is as below

Function

Public Function getAllPostalCod e(ByRef rsPostalCode As SqlClient.SqlDa taReader) As Boolean

Dim oCon As SqlClient.SqlCo nnection
Dim oCommand As SqlClient.SqlCo mmand

Dim SQL As String

Try
oCon = mdConnection.Ge tConnection

SQL = "SELECT * FROM Postal_Code"

oCommand = New SqlClient.SqlCo mmand(SQL, oCon)
rsPostalCode = oCommand.Execut eReader()

getAllPostalCod e = True
Catch
getAllPostalCod e = False
MsgBox(Err.Desc ription)
End Try

oCon.Close()
End Function


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

If Not oPostalCode.get AllPostalCode(r sPostalCode) Then Exit Sub
Aug 27 '07 #1
2 3605
phvfl
173 Recognized Expert New Member
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
Aaaaash
4 New Member
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
1652
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 planning on changing this in our code and I expect this to fix our problem. We have our connection pooling set to the default number of connections open. We probably have about 3-7 users concurrently using our web site. So, the problem isn't that we...
2
8089
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
1171
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 It's not working. What is wrong?
3
2000
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 Access Application blocks for .NET and am struggling to understand the following: 1. When creating a function that returns a datareader, there is a datareader instantiated inside the function. This datareader is then returned to the
11
8128
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 number) which is the last line of the following sub routine: ' procedure modifies elements of array and assigns ' new reference (note ByVal) Sub FirstDouble(ByVal array As Integer()) Dim i As Integer
5
7898
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 SqldataReader in the function where it is being created properly? If I close the SqlDataReader in the function my datareader returns nothing of course. So how do I code it properly to pass back a datareader and close it in the function?
1
3939
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 dataset and one that returns a datareader. I want to pass in the commandName, and a ParameterArray that holds the parameters I want to populate: Public Shared Function ExeCmd(ByVal CommandName As String, ByVal CmdParam as...
12
2593
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 by value temporaries are created?(I'm not touching yet the cases where standard allows optimizations from the side of implementations to avoid copying) If so, please quote part of the standard that says that. Assuming it is true, I can imagine two...
2
1500
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 the read() method. The page in question is a string matching search page (its a photo site and the photos have associated tags) that may return multiple results. I wish to display the first picture match and its details and then have a button that...
0
10168
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...
0
10008
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9959
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
8833
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...
1
7381
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5279
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
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.