Actually I didn't quite get your Select statement.
select
from table
where (id=@id
or @ID is null
)and (id=@name
or @name is null
)name
what it suppose to do ?There are few ways of doing this.
i) In table design,set default value to null
ii)In front end ,the way you are doing is correct.what if it is null ?
what are u writing for it ?
yeah,
it seems my code, but you use an immediate if
it is ok
i was only looking for a solution like a nullable parameters for string lik Int?
but String is a reference type!
amodius
Member
178 Points
382 Posts
how can i pass to SP a string with null value?
Aug 26, 2010 07:01 AM|LINK
hi there
i have a stored procedure like this
the problem is that i need define for parameter @name NULL, how can i do it?
in my code actually i use an IF
if (LocalCode != "") { cmd.Parameters.AddWithValue("@LocalCode", LocalCode); }
but i think it is not professional programming
smirnov
All-Star
23398 Points
4015 Posts
Re: how can i pass to SP a string with null value?
Aug 26, 2010 09:21 AM|LINK
Your code is correct and should work as expected.
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlparametercollection.addwithvalue.aspx
You can also do it in the following way:
cmd.Parameters.AddWithValue("@LocalCode", (LocalCode != "" ? LocalCode, DBNull.Value));
arefinn
Contributor
4992 Points
750 Posts
Re: how can i pass to SP a string with null value?
Aug 26, 2010 10:05 AM|LINK
Send DBNull.Value from your application to stored procedure.
KumarHarsh
All-Star
15133 Points
3647 Posts
Re: how can i pass to SP a string with null value?
Aug 26, 2010 10:08 AM|LINK
Actually I didn't quite get your Select statement.
what it suppose to do ?There are few ways of doing this.
i) In table design,set default value to null
ii)In front end ,the way you are doing is correct.what if it is null ?
what are u writing for it ?
Kumar Harsh
amodius
Member
178 Points
382 Posts
Re: how can i pass to SP a string with null value?
Aug 26, 2010 10:13 AM|LINK
yeah,
it seems my code, but you use an immediate if
it is ok
i was only looking for a solution like a nullable parameters for string lik Int?
but String is a reference type!
ok thanks