|
-
Jul 5th, 2005, 12:59 AM
#1
Thread Starter
Lively Member
passing NULL as parameter to SP
hi
i using exec SPName 'filterthis',1,NULL in query analyser. it works successfully.
i m accessing SQL stored proc in my page and i want to pass NULL as parameter from asp.net. but there is no enum for SqlDBtype.null. how can i pass NULL as parameter?
-
Jul 5th, 2005, 01:05 AM
#2
Re: passing NULL as parameter to SP
-
Jul 5th, 2005, 01:15 AM
#3
Thread Starter
Lively Member
Re: passing NULL as parameter to SP
 Originally Posted by mendhak
How about System.DBNull
im trying to pass as "@vsUserID", SqlDbType.Char, 8, System.DBNull
but its not working and its giving error:
'DBNull' is a type in 'system' cant be used as expression.
-
Jul 5th, 2005, 01:41 PM
#4
PowerPoster
Re: passing NULL as parameter to SP
I guess, its DBNull.value
-
Jul 5th, 2005, 03:26 PM
#5
Re: passing NULL as parameter to SP
You could also try just not setting a value.... by its very nature that would make it NULL.
Tg
-
Jul 5th, 2005, 04:10 PM
#6
Frenzied Member
Re: passing NULL as parameter to SP
System.Data.SqlTypes.SqlString.Null the value is not important it is used to get/set the .net value type value.... you can SqlString = "sdfgsgdfg" or qlString.Value = "sdgdfgsfgsdfgf" the correct way to get a String is String = SqlString.Value
p.s. a stored procedure with invalid number of parameters passed in will fail and I'm not sure you can create a parameter object with out setting a value. However if you set the parameters default value to NULL in the sp you can omit that parameter and any other with a default value set.
Magiaus
If I helped give me some points.
-
Jul 5th, 2005, 04:10 PM
#7
Frenzied Member
Re: passing NULL as parameter to SP
Magiaus
If I helped give me some points.
-
Jul 5th, 2005, 08:35 PM
#8
Re: passing NULL as parameter to SP
 Originally Posted by Magiaus
System.Data.SqlTypes.SqlString.Null the value is not important it is used to get/set the .net value type value.... you can SqlString = "sdfgsgdfg" or qlString.Value = "sdgdfgsfgsdfgf" the correct way to get a String is String = SqlString.Value
p.s. a stored procedure with invalid number of parameters passed in will fail and I'm not sure you can create a parameter object with out setting a value. However if you set the parameters default value to NULL in the sp you can omit that parameter and any other with a default value set.
You most certanly can.... I do it every day....If you create a parameter and don't set the value, and don't have a default value set, the parameter will be NULL. As long as you create it and append it, it won't (shouldn't) give you errors about missing a parameter.
Tg
-
Jul 6th, 2005, 11:05 AM
#9
Frenzied Member
Re: passing NULL as parameter to SP
Can you post a snippet of how your building the parameter? I don't doubt your right; I just want to see how your doing it. I usually just use null in C#...
Code:
SqlParameter param = new SqlParamater("@SeadchName", null);
and for instance it would bring any names matching search name or everything if null....
Magiaus
If I helped give me some points.
-
Jul 6th, 2005, 11:52 AM
#10
Re: passing NULL as parameter to SP
Same as you would if you were setting a value.... just leave off the value part of the CreateParameter.....
"@vsUserID", SqlDbType.Char, 8 <-- see? Just don't set the value.... create the parameter, just no value.
instead of
"@vsUserID", SqlDbType.Char, 8, System.DBNull
Tg
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|