Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Cscode:
string FIRST_NAME = txtFirstName.Text.Length == 0 ? null : txtFirstName.Text;


SP:
cmd.Parameters.AddWithValue("@FIRST_NAME", FIRST_NAME);



Error:
INSERT_NEW_STARTER_DETAILS' expects parameter '@FIRST_NAME', which was not supplied.

I am trying insert null value into database when the textbox is empty. but the SP insert the data when there is text in textbox and not inserting when it is empty (null).

Is there any other easy way to achieve it.

Thanks,
Sathish
Posted
Updated 21-Oct-13 3:02am
v2

1 solution

Hello,

You can try this,
add null as default paramter value and don't pass any value if you want it to be null

example:

In your Sp
create procedure sp_PassNullValueInSp(@para1 varhcra(10), @para2 varchar(10)= null)


C# Code
cmd.Parameters.AddWithValue("@para1", "value1");
//No need to pass para2 if it is null
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900