Hello,
This my a method to call a stored proce and uses a DataReader to read
the data
in the below method I am trying to assign a null value to my datareader
variable
Dim datareader As SqlDataReader
datareader = null
but it doesn't accept.
*************** *************** ****
Public Function GetDealers() As SqlDataReader
Dim strSql As String
Dim datareader As SqlDataReader
Try
Dim conn As IDbConnection = GetConnection()
Try
Dim cmd As IDbCommand = conn.CreateComm and()
strSql = "USP_GetDealers "
cmd.CommandText = strSql
cmd.CommandType = CommandType.Sto redProcedure
conn.Open()
datareader =
cmd.ExecuteRead er(CommandBehav ior.CloseConnec tion)
Finally
End Try
Catch ex As Exception
End Try
Return datareader
End Function
*************** *************** *************** ****
Can some one help me with this..
-L 4 2529
That would work in C#, but since you're using VB.NET you should set it to
Nothing instead of Null.
datareader = Nothing
--
I hope this helps,
Steve C. Orr, MCSD, MVP http://SteveOrr.net
"Learner" <pr****@gmail.c om> wrote in message
news:11******** **************@ t31g2000cwb.goo glegroups.com.. . Hello,
This my a method to call a stored proce and uses a DataReader to read the data
in the below method I am trying to assign a null value to my datareader variable Dim datareader As SqlDataReader datareader = null but it doesn't accept. *************** *************** **** Public Function GetDealers() As SqlDataReader Dim strSql As String Dim datareader As SqlDataReader Try Dim conn As IDbConnection = GetConnection() Try Dim cmd As IDbCommand = conn.CreateComm and() strSql = "USP_GetDealers " cmd.CommandText = strSql cmd.CommandType = CommandType.Sto redProcedure conn.Open() datareader = cmd.ExecuteRead er(CommandBehav ior.CloseConnec tion) Finally End Try Catch ex As Exception End Try Return datareader End Function *************** *************** *************** ****
Can some one help me with this.. -L
I don't think you can, DataReader objects have to be instantiated by using an
ExecuteReader method.
"Learner" wrote: Hello,
This my a method to call a stored proce and uses a DataReader to read the data
in the below method I am trying to assign a null value to my datareader variable Dim datareader As SqlDataReader datareader = null but it doesn't accept. *************** *************** **** Public Function GetDealers() As SqlDataReader Dim strSql As String Dim datareader As SqlDataReader Try Dim conn As IDbConnection = GetConnection() Try Dim cmd As IDbCommand = conn.CreateComm and() strSql = "USP_GetDealers " cmd.CommandText = strSql cmd.CommandType = CommandType.Sto redProcedure conn.Open() datareader = cmd.ExecuteRead er(CommandBehav ior.CloseConnec tion) Finally End Try Catch ex As Exception End Try Return datareader End Function *************** *************** *************** ****
Can some one help me with this.. -L
Hello ,
Thans for the quick responses.
If I don't assign a default value a green line appears underneath the
'End Function' and when I mouse hover on it it says
'Function 'GetDealers' doesn't return a value on all code paths. Anull
reference could occur at run time when the result is used'
So like Steve mentioned I assigned it with Nothing and modified it
slightly
Public Function GetDealers() As SqlDataReader
Dim strSql As String
Dim datareader As SqlDataReader
datareader = Nothing
Try
Dim conn As IDbConnection = GetConnection()
Try
Dim cmd As IDbCommand = conn.CreateComm and()
strSql = "USP_GetDealers "
cmd.CommandText = strSql
cmd.CommandType = CommandType.Sto redProcedure
conn.Open()
datareader =
cmd.ExecuteRead er(CommandBehav ior.CloseConnec tion)
Finally
End Try
Catch ex As Exception
End Try
Return datareader
End Function
executed the code and it works fine and also there is no green line
underneath the "End Function" as I have moved "Return datareader" out
of the Try Catch block.
Hope the way I am doing it looks perfectly alright. Please advise if
itsn't and how do I it. Because I want to do it right :) Offcourse all
of us.
Thanks
-L
Yes, that is a perfectly valid design.
I do hope you plan to put something in the catch block though, otherwise you
should probably remove "ex as Exception" to help optimize the performance.
--
I hope this helps,
Steve C. Orr, MCSD, MVP http://SteveOrr.net
"Learner" <pr****@gmail.c om> wrote in message
news:11******** **************@ t31g2000cwb.goo glegroups.com.. . Hello , Thans for the quick responses.
If I don't assign a default value a green line appears underneath the 'End Function' and when I mouse hover on it it says
'Function 'GetDealers' doesn't return a value on all code paths. Anull reference could occur at run time when the result is used'
So like Steve mentioned I assigned it with Nothing and modified it slightly
Public Function GetDealers() As SqlDataReader Dim strSql As String Dim datareader As SqlDataReader datareader = Nothing Try Dim conn As IDbConnection = GetConnection() Try Dim cmd As IDbCommand = conn.CreateComm and() strSql = "USP_GetDealers " cmd.CommandText = strSql cmd.CommandType = CommandType.Sto redProcedure conn.Open() datareader = cmd.ExecuteRead er(CommandBehav ior.CloseConnec tion) Finally End Try Catch ex As Exception End Try Return datareader End Function
executed the code and it works fine and also there is no green line underneath the "End Function" as I have moved "Return datareader" out of the Try Catch block.
Hope the way I am doing it looks perfectly alright. Please advise if itsn't and how do I it. Because I want to do it right :) Offcourse all of us.
Thanks -L This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: sneill |
last post by:
How is it possible to take the value of a variable (in this case,
MODE_CREATE, MODE_UPDATE, etc) and use that as an object property name?
In the following example I want 'oIcon' object to have the properties:
mode1, mode2, and mode3.
This seems simple but I can't quite figure it out...
Any ideas anyone?
|
by: TomislaW |
last post by:
I have integers in my database that can be null. I read them with
SqlDataReader and show them to Repeater. Since integer can not be null in
c#, I set null integer to -1. My project is 3-tier and it is very
complicated to check in data tier if it is null set -1, then in business
tier if it is -1 do not calculate with him and then in presentation tier "do
not show if it is -1". Is there any better solution for that?
|
by: Chris |
last post by:
Hi,
I have an SQL Query that loads a SQLDataReader object.
The returned record has bit datatype columns that I use to provide
true/false values.
I can't get a definite answer googling on how to test if this field is null.
I get casting errors, and can't check for null on a null data value errors
|
by: Michael Bohman |
last post by:
Hi, i have a small problem with assigning a database value to a
RadioButtonList control. On my form i have 3 user admin=1, premium=2 and
basic=3, theese values is stored in an access database in a text string.
My problem is that when i'm loading my form, it uses a repeater control
for each user by the way, I can't find a way to assign either of these
values to the RadioButtonList Control. I can read them from the database
but i wan't the...
|
by: Jim McGivney |
last post by:
In asp 2.0 I am trying to insert a row using a detailsview control connected
to an accessDataSource. I get the error message below. I am having trouble
identifing which data field is causing the problem. Any suggestings are
welcomed.
Jim
*************
You tried to assign the Null value to a variable that is not a Variant data
type.
Description: An unhandled exception occurred during the execution of the
current web request. Please...
| |
by: MLH |
last post by:
I have 2 lines in a procedure that assign MyVariant a value - line
#238 and line #491. When line #238 runs, the value is 152. When line
#491 runs, the DLookup function returns Null. I would expect
MyVariant to be Null. But it is not. Its value is still reported as
152. I'm able to confirm its value is not Null by running
IsNull(MyVariant) immediately after line #491.
238 MyVariant = Forms!frmUSPSReturnReceipts!RROLAXchewsurBox.Column(3)...
|
by: Liam Mac |
last post by:
Hi All,
Can anyone direct me or provide advice on how I can assign a null value to a
date variable in vb.net.
Basically what I'm doing is that I'm looping through a recordset where I
have three date fields that may or maynot have date values, if no date values
exists in the source field, the value is null. but when I pass a record from
the recordset to SQL command parameter query for record insertion into a
different table, the date...
|
by: joelranck |
last post by:
I'm having a problem figuring out how to evaluate a value read from a
SqlConnection and then assign a column based on that evaluation into my
DataGrid. Basically when the DB is queried I want to check if a value
is 1 or 0 in a specific field.. If so then assign corresponding Yes or
No into the DataGrid. The question is really two parts how can I
evaluate a DataReader value and how can I manually bind a new value
into a DataGrid?
Thanks...
|
by: =?Utf-8?B?R3JlZw==?= |
last post by:
I have the following three files.
1. Users.aspx is a webpage that uses the <asp:ObjectDataSourcecontrol to
populate a simple <asp:ListBoxcontrol.
2. The UserDetails.cs file creates a Namespace named UserComponents and
creates an object named UserDetails.
3. The UserDB.cs file retrieves the actual data from the database.
The code below has been condensed and only includes two fields from my
datasource. I actually am also
retrieving...
|
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: 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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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: 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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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: 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...
| |