I'm trying to pass a sqlDataReader from a called function to a calling
function but got nothing back and a message saying "An unhandled
exception of type 'System.NullRef erenceException ' occurred in
Throw.exe. Object reference not set to an instance of an object."
Here is my code:
Public Function testint() As String
'Nothing returns here, plus the error above
Dim xp As SqlDataReader = getStoreProcedu res("StoreProce dure")
End Function
Public Function getStoreProcedu res() As SqlDataReader
Dim sp As SqlDataReader =
CCMSDB.DBDataRe ader("procSelec tBatchReports")
'This sp.Read returns rows displayed in the message box fine.
While sp.Read
MsgBox(sp("Stor eProcedure"))
End While
'This code works fine until here
getStoreProcedu res = sp
'After this, when it returns to Testint, it will blow up
end function
Can anyone help please? I'm new to VB.NET. Thanks in advance,
James 6 9040
Hi James,
There doesn't seem to be anything wrong with the code that you have shown,
except that it isn't the code that you are using!!
One getStoreProcedu res takes a parameter.
Dim xp As SqlDataReader = getStoreProcedu res("StoreProce dure")
The other doesn't
Public Function getStoreProcedu res() As SqlDataReader
This isn't the cause of the Exception, but it may be the cause of me not
being able to see what is!!
Regards,
Fergus
try
Return sp
instead of getstoreprocedu ces=sp
"James P." <jp***@sandsexp o.com> wrote in message
news:bd******** *************** ***@posting.goo gle.com... I'm trying to pass a sqlDataReader from a called function to a calling function but got nothing back and a message saying "An unhandled exception of type 'System.NullRef erenceException ' occurred in Throw.exe. Object reference not set to an instance of an object."
Here is my code: Public Function testint() As String 'Nothing returns here, plus the error above Dim xp As SqlDataReader = getStoreProcedu res("StoreProce dure") End Function Public Function getStoreProcedu res() As SqlDataReader Dim sp As SqlDataReader = CCMSDB.DBDataRe ader("procSelec tBatchReports") 'This sp.Read returns rows displayed in the message box fine. While sp.Read MsgBox(sp("Stor eProcedure")) End While 'This code works fine until here getStoreProcedu res = sp 'After this, when it returns to Testint, it will blow up end function
Can anyone help please? I'm new to VB.NET. Thanks in advance, James
Hi Mat,
For backwards compatibility (I believe), assignment to the Function name
is a legitimate way to return a value
Function Foo As String
Foo = "I'm going places!!"
End Function
Regards,
Fergus
"Fergus Cooney" <fi******@tesco .net> wrote in message news:<uD******* *******@TK2MSFT NGP10.phx.gbl>. .. Hi James,
There doesn't seem to be anything wrong with the code that you have shown, except that it isn't the code that you are using!!
One getStoreProcedu res takes a parameter. Dim xp As SqlDataReader = getStoreProcedu res("StoreProce dure")
The other doesn't Public Function getStoreProcedu res() As SqlDataReader
This isn't the cause of the Exception, but it may be the cause of me not being able to see what is!!
Regards, Fergus
Fergus,
Thanks a lot for pointing out my classic mistake. It works after I modified it.
James
Hi James,
Strange, I'd have expected the compiler to pick that one up.
No matter - you're back on the road again. :-)
Regards,
Fergus
Fergus,
Thanks a lot for pointing out the missing parameter in the function. It
works now.
James
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Mike Dinnis |
last post by:
Hi,
I've been working through a number of turorials to try to learn more about
retrieving data from a SQL database. I think i've mastered techniques where
i create a sql string in the page and pass it to the Db and retrieveing data
from a stored procedure, but I can't get the hang of parameters.
I have a method where I can get the parameters passed to the sp but it
doesn't want to return any results. Here's a copy of my code:
|
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 from the database.
However, the two classes don't appear to have any common interfaces that
would allow me to enumerate the fields. Yet, when you databind you can pass
either of these classes (as well as many others) and .NET somehow knows how...
|
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...
|
by: vengala s reddy |
last post by:
i have login.aspx, login.vb, i have my stored procedures in login.vb
in login.aspx
<%@ Page Language="vb" src="/MyTime/com/login.vb"
Inherits="Enter.MyTime"%>
in login.vb
Public Sub EnterMyTime(ByVal ID As String, ByVal PWD As String)as
dataset
|
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
| |
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
|
by: paapa21 |
last post by:
I want to Declear a variable as SqlDataReader in ASP 2.0. But when i do so it
tells me SqlDataReader is not define. This same code works in my previous
application in ASP 1.0. Has this change? Can someone show me how to do this.
Below is the function and the line of the error is bold.
Function GetUniversity() As String
Dim Unipayment As New UnipaymentDB
Dim CIDR As SqlDataReader =
Unipayment.StudentState(Request.Params("StudentID"))
|
by: rn5a |
last post by:
A SqlDataReader is populated with the records from a SQL Server 2005 DB
table. The records retrieved depends upon 2 conditions (the conditions
depend on what a user selects in an ASPX page). If condition1 is true,
then the SqlDataReader will be populated with the records existing in
table1 & will return 0 to the calling function but if condition2 is
true, then the SqlDataReader will be populated with the records from
another table named...
|
by: Aaaaash |
last post by:
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
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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...
| |
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...
|
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,...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 we have to send another system
| |
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...
| |