M
Matt Jensen
Howdy all
I know this is a common question as I've searched a lot of this NG on the
topic, however I haven't been able to find an answer.
All I want to do is pass a DateTime value to a SQL Server SP DateTime
parameter, and either pass a web form text field value to it if there is one
or else null, I don't want to start another discussion about structs /
datetimes being able to accept nulls, I just would really like it to
work...!
So here is a snippet of what I've tried:
SqlDateTime dateStartDate = SqlDateTime.Null; //(also tried =
System.Convert.DBNull;
if (tbxStartDate.Text!="")
{
dateStartDate = Convert.ToDateTime(tbxStartDate.Text);
}
/*Also tried the following with no success.
else
{
dateStartDate = DBNull.Value;
}*/
//Set SQL parameters and populate with form values
sqlCommand1.Parameters.Add("@StartDate", SqlDbType.SmallDateTime).Value =
dateStartDate;
If you could give me the answer/solution I'd be most happy.
Thanks
Cheers
Matt
I know this is a common question as I've searched a lot of this NG on the
topic, however I haven't been able to find an answer.
All I want to do is pass a DateTime value to a SQL Server SP DateTime
parameter, and either pass a web form text field value to it if there is one
or else null, I don't want to start another discussion about structs /
datetimes being able to accept nulls, I just would really like it to
work...!
So here is a snippet of what I've tried:
SqlDateTime dateStartDate = SqlDateTime.Null; //(also tried =
System.Convert.DBNull;
if (tbxStartDate.Text!="")
{
dateStartDate = Convert.ToDateTime(tbxStartDate.Text);
}
/*Also tried the following with no success.
else
{
dateStartDate = DBNull.Value;
}*/
//Set SQL parameters and populate with form values
sqlCommand1.Parameters.Add("@StartDate", SqlDbType.SmallDateTime).Value =
dateStartDate;
If you could give me the answer/solution I'd be most happy.
Thanks
Cheers
Matt