473,498 Members | 1,532 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

default value assigned to SqlParameter that can be overwritten

Hi,

I want to assign a default value of DBNull.Value to my
stored procedure parameter, but also have the ability to
overwrite it, so:
SqlParameter param = new SqlParameter
("@EmployeeId",SqlDbType.Char,10);
param.Value = DBNull.Value; //but want to overwrite maybe
cmd.Parameters.Add(param);

How can I do this?

thanks in advance
Nov 16 '05 #1
2 3838
Hello Confused,

cmd.Parameters.Add(new SqlParameter("@EmployeeId",SqlDbType.Char,10));
cmd.Parameters["@EmployeeId"].IsNullable = true;
cmd.Parameters["@EmployeeId"].Value = DBNull.Value;

// later

cmd.Parameters["@EmployeeId"].Value = somethingElse;

Or, to be more efficient:

SqlParameter param = new SqlParameter("@EmployeeId",SqlDbType.Char,10);
param.IsNullable = true;
param.Value = DBNull.Value;
cmd.Parameters.Add(param);

// later

cmd.Parameters["@EmployeeId"].Value = somethingElse;

// or, if you still have the param reference around, you can still use it:

param.Value = somethingElse;

--Bob

"confused" <an*******@discussions.microsoft.com> wrote in message
news:06****************************@phx.gbl...
Hi,

I want to assign a default value of DBNull.Value to my
stored procedure parameter, but also have the ability to
overwrite it, so:
SqlParameter param = new SqlParameter
("@EmployeeId",SqlDbType.Char,10);
param.Value = DBNull.Value; //but want to overwrite maybe
cmd.Parameters.Add(param);

How can I do this?

thanks in advance

Nov 16 '05 #2
cheers bob, i'll give it a go
-----Original Message-----
Hello Confused,

cmd.Parameters.Add(new SqlParameter ("@EmployeeId",SqlDbType.Char,10));cmd.Parameters["@EmployeeId"].IsNullable = true;
cmd.Parameters["@EmployeeId"].Value = DBNull.Value;

// later

cmd.Parameters["@EmployeeId"].Value = somethingElse;

Or, to be more efficient:

SqlParameter param = new SqlParameter ("@EmployeeId",SqlDbType.Char,10);param.IsNullable = true;
param.Value = DBNull.Value;
cmd.Parameters.Add(param);

// later

cmd.Parameters["@EmployeeId"].Value = somethingElse;

// or, if you still have the param reference around, you can still use it:
param.Value = somethingElse;

--Bob

"confused" <an*******@discussions.microsoft.com> wrote in messagenews:06****************************@phx.gbl...
Hi,

I want to assign a default value of DBNull.Value to my
stored procedure parameter, but also have the ability to overwrite it, so:
SqlParameter param = new SqlParameter
("@EmployeeId",SqlDbType.Char,10);
param.Value = DBNull.Value; //but want to overwrite maybe cmd.Parameters.Add(param);

How can I do this?

thanks in advance

.

Nov 16 '05 #3

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

Similar topics

5
4082
by: Michael Albanese | last post by:
I recently read an article that mentioned adding code to the onload event to "register a default button". The behavior i am after is that when the user hits enter, the form submits. Does...
0
3682
by: LU | last post by:
I have a datagrid for viewing and deleting. Under that I have a drop down with binded info and a button to add the select drop down item into database. 1User can view datagrid and delete info....
4
14048
by: Laszlo Csabi | last post by:
Hi Folks, Can someone explain me why I'm getting the following error? The error message I got is : "Parameter count does not match Parameter Value count."
29
3014
by: John Wood | last post by:
Even though CSC does its best to detect use of unassigned variables, it often misses it... for example if you just declare a double in a class without assigning a default value, it has a default...
2
3153
by: Joey | last post by:
Hi There, I am trying to get the selected value of a listbox when I click a button, everything works ok and I can bind the list and when I have a basic page and click a button to invoke a sub it...
4
4691
by: Patrick Olurotimi Ige | last post by:
I have a DropDown Lsit set to ddlGetDebtor.Items.Insert(0, "-Select Debtor Code-") which is setting the "-Select Debtor Code-" to be default And on PostBack i'm passng:- Cmd.Parameters.Add(New...
74
15865
by: Zytan | last post by:
I have a struct constructor to initialize all of my private (or public readonly) fields. There still exists the default constructor that sets them all to zero. Is there a way to remove the...
6
7822
by: Tim Zych | last post by:
' Declare a new parameter object Dim param() As SqlParameter = New SqlParameter(0) {} ' Set this to null and make it an InputOutput parameter param(0) = New SqlParameter("@Something, DBNull.Value)...
2
2408
by: preeti13 | last post by:
Hi guys i am here with my another probelm please help me.trying insert the value into the data base but getting the null value error .I am getting thsi error Cannot insert the value NULL into...
0
7005
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...
0
7168
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,...
0
5465
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,...
1
4916
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
4595
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
3096
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
1424
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 ...
1
659
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
293
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...

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.