473,467 Members | 1,592 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Sending stored proc Parameter

Rob
What is the syntax to send a null value as a parameter ?

cmd.Parameters.Add("@Year", Convert.ToInt32(strYear))

in cases where strYear = ""

I want to send ...

cmd.Parameters.Add("@Year", Null)

But the syntax is incorrect....

How would I send it ?
Aug 7 '07 #1
9 1137
On Aug 7, 12:19 pm, "Rob" <ro...@yahoo.comwrote:
What is the syntax to send a null value as a parameter ?

cmd.Parameters.Add("@Year", Convert.ToInt32(strYear))

in cases where strYear = ""

I want to send ...

cmd.Parameters.Add("@Year", Null)

But the syntax is incorrect....

How would I send it ?
Will it accept DbNull?

Thanks,

Seth Rowe

Aug 7 '07 #2
Rob
No, I tried that as well, but it did not like that either...

Thanks
Rob
"rowe_newsgroups" <ro********@yahoo.comwrote in message
news:11********************@22g2000hsm.googlegroup s.com...
On Aug 7, 12:19 pm, "Rob" <ro...@yahoo.comwrote:
>What is the syntax to send a null value as a parameter ?

cmd.Parameters.Add("@Year", Convert.ToInt32(strYear))

in cases where strYear = ""

I want to send ...

cmd.Parameters.Add("@Year", Null)

But the syntax is incorrect....

How would I send it ?

Will it accept DbNull?

Thanks,

Seth Rowe

Aug 7 '07 #3
Hi Rob,

Did you try DbNull.Value ?

Regards,
Bill.
"Rob" <ro***@yahoo.comwrote in message
news:EP******************************@comcast.com. ..
No, I tried that as well, but it did not like that either...

Thanks
Rob
"rowe_newsgroups" <ro********@yahoo.comwrote in message
news:11********************@22g2000hsm.googlegroup s.com...
>On Aug 7, 12:19 pm, "Rob" <ro...@yahoo.comwrote:
>>What is the syntax to send a null value as a parameter ?

cmd.Parameters.Add("@Year", Convert.ToInt32(strYear))

in cases where strYear = ""

I want to send ...

cmd.Parameters.Add("@Year", Null)

But the syntax is incorrect....

How would I send it ?

Will it accept DbNull?

Thanks,

Seth Rowe

Aug 7 '07 #4
"Rob" <ro***@yahoo.comschrieb
What is the syntax to send a null value as a parameter ?

cmd.Parameters.Add("@Year", Convert.ToInt32(strYear))

in cases where strYear = ""

I want to send ...

cmd.Parameters.Add("@Year", Null)

But the syntax is incorrect....

How would I send it ?
'untested, without string validation:
shared function ABC(byval s as string) as object

if s.length=0 then return dbnull.value
return cint(s)

end function

cmd.Parameters.Add("@Year", ABC(strYear))
Armin
Aug 7 '07 #5
Rob
Thanks Bill,

Yes, looks like that will work... I should have known...

Rob
"Bill McCarthy" <Bi**@NOSPAM.comwrote in message
news:O9**************@TK2MSFTNGP06.phx.gbl...
Hi Rob,

Did you try DbNull.Value ?

Regards,
Bill.
"Rob" <ro***@yahoo.comwrote in message
news:EP******************************@comcast.com. ..
>No, I tried that as well, but it did not like that either...

Thanks
Rob
"rowe_newsgroups" <ro********@yahoo.comwrote in message
news:11********************@22g2000hsm.googlegrou ps.com...
>>On Aug 7, 12:19 pm, "Rob" <ro...@yahoo.comwrote:
What is the syntax to send a null value as a parameter ?

cmd.Parameters.Add("@Year", Convert.ToInt32(strYear))

in cases where strYear = ""

I want to send ...

cmd.Parameters.Add("@Year", Null)

But the syntax is incorrect....

How would I send it ?

Will it accept DbNull?

Thanks,

Seth Rowe


Aug 7 '07 #6
Rob wrote:
What is the syntax to send a null value as a parameter ?

cmd.Parameters.Add("@Year", Convert.ToInt32(strYear))

in cases where strYear = ""

I want to send ...

cmd.Parameters.Add("@Year", Null)

But the syntax is incorrect....

How would I send it ?
You create a parameter with the correct type and set the value to DBNull:

cmd.Parameters.Add("@Year", SqlDbType.Int).Value = DBNull.Value

--
Göran Andersson
_____
http://www.guffa.com
Aug 7 '07 #7
No problem Rob, it catches me out plenty of times <g>
"Rob" <ro***@yahoo.comwrote in message
news:9I******************************@comcast.com. ..
Thanks Bill,

Yes, looks like that will work... I should have known...

Rob
"Bill McCarthy" <Bi**@NOSPAM.comwrote in message
news:O9**************@TK2MSFTNGP06.phx.gbl...
>Hi Rob,

Did you try DbNull.Value ?

Regards,
Bill.
"Rob" <ro***@yahoo.comwrote in message
news:EP******************************@comcast.com ...
>>No, I tried that as well, but it did not like that either...

Thanks
Rob
"rowe_newsgroups" <ro********@yahoo.comwrote in message
news:11********************@22g2000hsm.googlegro ups.com...
On Aug 7, 12:19 pm, "Rob" <ro...@yahoo.comwrote:
What is the syntax to send a null value as a parameter ?
>
cmd.Parameters.Add("@Year", Convert.ToInt32(strYear))
>
in cases where strYear = ""
>
I want to send ...
>
cmd.Parameters.Add("@Year", Null)
>
But the syntax is incorrect....
>
How would I send it ?

Will it accept DbNull?

Thanks,

Seth Rowe

Aug 7 '07 #8
On Aug 7, 12:48 pm, "Bill McCarthy" <B...@NOSPAM.comwrote:
Hi Rob,

Did you try DbNull.Value ?

Regards,
Bill.

"Rob" <ro...@yahoo.comwrote in message

news:EP******************************@comcast.com. ..
No, I tried that as well, but it did not like that either...
Thanks
Rob
"rowe_newsgroups" <rowe_em...@yahoo.comwrote in message
news:11********************@22g2000hsm.googlegroup s.com...
On Aug 7, 12:19 pm, "Rob" <ro...@yahoo.comwrote:
What is the syntax to send a null value as a parameter ?
>cmd.Parameters.Add("@Year", Convert.ToInt32(strYear))
>in cases where strYear = ""
>I want to send ...
>cmd.Parameters.Add("@Year", Null)
>But the syntax is incorrect....
>How would I send it ?
Will it accept DbNull?
Thanks,
Seth Rowe- Hide quoted text -

- Show quoted text -
Thats what I meant - do I get partial credit for saying DbNull?

:-)

Thanks,

Seth Rowe

Aug 7 '07 #9
Hi Seth,

Sure do :) For some reason I always look for DbNull.Default only to realize
it's DbNull.Value I need.

"rowe_newsgroups" <ro********@yahoo.comwrote in message
news:11**********************@x40g2000prg.googlegr oups.com...
>
Thats what I meant - do I get partial credit for saying DbNull?

:-)

Thanks,

Seth Rowe
Aug 8 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Nyul | last post by:
Gurus, I have a verb big problem which I'm unable to explain. We have a DB2 V6.1.0 on AIX 4.3 I want to make a C stored procedure which at the end will be called by a PHP script. The...
1
by: Eric Land | last post by:
Help! I'm trying to call a parameterized stored proc in ASP.NET in VB. I am creating a command object and creating a parametr list, and assigning a value from a session variable (this is working)...
6
by: Paul M | last post by:
Hi All, I'm currently writing a z/OS DB2 Stored Proc in C, using an example from the IBM Stored Procedure guide (SG24-7083-00). The database calls to read and update the database work...
0
by: balaji krishna | last post by:
Hi, I need to handle the return set from COBOL stored procedure from my invoking Java program. I do not know, how many rows the stored proc SQL fetches.I have declared the cursor in that proc, but i...
7
by: ashtek | last post by:
Hi, I have a generic function that executes a stored procedure & returns a data table. Code: === public static DataTable ExecuteStoredProcedure(string strProc,SqlParameter paramArray) {...
3
by: JJ | last post by:
When running an sql stored procedure, is it possible to pass in the sortexpression as a parameter? When I try it all the other parameters operate as expected, but the rows are not sorted. The...
2
by: =?Utf-8?B?Vmlua2k=?= | last post by:
Hello Everyone, I can successfully insert and update the oracle database by calling a oracles stored proc from my .net code. This oracle stored proc is returning some value. I cannot see that...
1
by: =?Utf-8?B?Vmlua2k=?= | last post by:
Hello Everyone, I can successfully insert and update the oracle database by calling a oracles stored proc from my .net code. This oracle stored proc is returning some value. I cannot see that...
0
by: mirandacascade | last post by:
Questions toward the bottom of the post. Situation is this: 1) Access 97 2) SQL Server 2000 3) The Access app: a) sets up pass-thru query b) .SQL property of querydef is a string, the...
7
by: jamesclose | last post by:
My problem is this (apologies if this is a little long ... hang in there): I can define a function in VB.NET with optional parameters that wraps a SQL procedure: Sub Test(Optional ByVal Arg1...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
1
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...
0
tracyyun
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...
0
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.