Insert DateTime as Null

Joined
Feb 2, 2009
Messages
2
Reaction score
0
The code will insert DateTime as 01 Jan 1910, how can it be inserted as blank ?

Code:
DateTime Date2;

[B]WebForm[/B]
if (txtDate.Text.ToString() == "")
{
Date2 = Convert.ToDateTime("1910/Jan/01");
}
else
{
Date2 = Convert.ToDateTime(txtDate.Text.ToString());
}

[B]DB[/B]
if (demItem.InvoiceDate.ToString("yyyy/MM/dd") == "1910/Jan/01")
{
cm.Parameters["@invoiceDate"].Value = DBNull.Value;
}
else
{
cm.Parameters["@invoiceDate"].Value = Convert.ToDateTime(Date2);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top