I am trying to pass default to SQL Server in c#.
This code passes null. Is there any way to pass default?
foreach (SqlParameter Parameter in command.Parameters)
{
if (Convert.ToString(Parameter.Value) == "")
{
Parameter.Value = DBNull.Value;
}
}
Here is another solution of sorts — it appears to search the stored procedure for parameter default values (literally, a pattern search for the assignment in the declaration of the variable), and return any default values that are found. So…you could call this procedure from your c# app to get all of your default values, assign them to local C# vars, and then use them when you call your other procedure.
http://www.codeproject.com/Articles/12939/Figure-Out-the-Default-Values-of-Stored-Procedure
And here is how you could find the default value on a table itself:
(you might need to strip the parenthesis off the returned value)
Good luck!