I have written a SQL Server stored procedure that includes a DateTime parameter. This parameter could be null or contain a valid date value.
So the definition of my variable in my procedure is below:
@piPurchase_Date DATETIME = NULL
From C# I add the parameter as follows:
SqlParameter parameter = new SqlParameter("@piPurchase_Date", SqlDbType.DateTime);
parameter.Value=datePurchaseIssueDate.Checked ? datePurchaseIssueDate.Value : SqlDateTime.Null;
So far all seems OK but when I call the Update method on the DataAdaptor I receive the following error:
Failed to convert parameter value from a SqlDateTime to a DateTime.
Any ideas?
I'm using SQL Server 2008 and C#4.0
Thanks in advance
String.Emptyor""and this is converted to aNULLDateTimevalue.paramter.Value = datePurchaseIssueDate.Checked ? (DateTime?) datePurchaseIssueDate.Value : null;nullsection withDbNull.Value