Ternary Operator Problem

Posted by Paraszalariya12 under C# on 4/11/2013 | Points: 10 | Views : 2167 | Status : [Member] | Replies : 1
Hello I have an One variable DateTime reg_date and One Textbox txt_reg_date.Now I want to store textbox value in reg_date variable. when textbox pass null value that time check if textbox=null then in variable store null value but that is not work properly...

DateTime reg_date;

reg_date= txt_reg_date.Text != string.Empty ? (DateTime?)Convert.ToDateTime( txt_reg_date.Text).Date : null;

but this is not working that display error.....




Responses

Posted by: Naraayanan on: 4/12/2013 [Member] Starter | Points: 25

Up
0
Down
Hi
try this way.
 Nullable<DateTime> reg_date = null;

reg_date = textBox1.Text == string.Empty ? null : (DateTime?)(Convert.ToDateTime(textBox1.Text));




Regards,
Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/
http://abaprocker.blogspot.com/

Paraszalariya12, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response