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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Vijay YadavPosted Jan 16, 2012, 5:13 AM
Check this,
string strDate="";
if(datepicker1.checked==false)
{
strDate="null";
}
else
{
strDate=datepicker1.value.Tostring("dd/MM/yyyy");
}
Abdu RafeeqPosted Jan 16, 2012, 10:37 PM
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.
Suthish NairPosted Jan 16, 2012, 8:12 AM
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.
AartiPosted Jan 16, 2012, 5:39 AM
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);
}
Abdu RafeeqPosted Jan 16, 2012, 4:35 AM
Jignesh TrivediPosted Jan 16, 2012, 3:12 AM
I want to just few modification on arti code.
DateTime? d;
if (checkBox1.IsChecked == true)
{
d= Convert.ToDateTime(datePicker1.Text);
}
else
{
d = null;
}
AartiPosted Jan 16, 2012, 2:47 AM
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);
}