how Retrive Null value from Datetime picker?
here i declared datetime variable and i want assign null value if check box uncliked within datetime picker....
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Vijay YadavRank #1,637 · 943 reputationPosted Jan 16, 2012, 12:13 AM EST
Check this,
string strDate="";
if(datepicker1.checked==false)
{
strDate="null";
}
else
{
strDate=datepicker1.value.Tostring("dd/MM/yyyy");
}
AartiRank #2,383 · 594 reputationPosted Jan 15, 2012, 9:47 PM EST
try with this code:
DateTime d = Convert.ToDateTime(datePicker1.Text);
if (checkBox1.IsChecked == true)
{
MessageBox.Show("" + d);
}
else
{
d = Convert.ToDateTime(null);
MessageBox.Show("" + d);
}
Jignesh TrivediRank #16 · 50.3K reputationPosted Jan 15, 2012, 10:12 PM EST
I want to just few modification on arti code.
DateTime? d;
if (checkBox1.IsChecked == true)
{
d= Convert.ToDateTime(datePicker1.Text);
}
else
{
d = null;
}
Abdu Rafeeq109 reputationPosted Jan 15, 2012, 11:35 PM EST
AartiRank #2,383 · 594 reputationPosted Jan 16, 2012, 12:39 AM EST
hi use this:
DateTime d = Convert.ToDateTime(datePicker1.Text);
if (checkBox1.IsChecked == true)
{
MessageBox.Show("" + d);
}
else
{
string dt = Convert.ToString(d);
dt = null;
MessageBox.Show("" + dt);
}
Suthish NairRank #92 · 22.8K reputationPosted Jan 16, 2012, 3:12 AM EST
2. Set the column default value as null.
3. (checkBox1.IsChecked == true) ? Convert.ToDateTime(datePicker1.Text); Pass the DatePicker value only if the check box is selected other wise not.
Abdu Rafeeq109 reputationPosted Jan 16, 2012, 5:37 PM EST
Msg 8114, Level 16, State 1, Procedure sales_new_master, Line 0
Error converting data type nvarchar to datetime.
i tried to insert null when check box uncliked,,i set
1. table column accept null value.
2. column default value as null.