Reputation: 1429
I have a variable that receives DATETIME type ,And sometimes comes from DB NULL variable So I have this code .
DateTime? d;
DateTime dtq;
don.Date_appeal_donor= d = DateTime.TryParse(dr["Date_"].ToString(), out dtq) ? dtq : (DateTime?)null;
And I can not change the format to "dd / MM / yyyy" Does anyone have a solution?
You're right, now I realized that only when it comes to DATAGRIDVIEW It changes the display This is in wpf. So I fill the data grid
dataGrid1.ItemsSource= DAL.LoadCollectionData();
And here I am stuck
Upvotes: 0
Views: 275
Reputation: 10941
You can use DateTime.TryParseExact
like this:
DateTime dtq;
DateTime? d;
don.Date_appeal_donor = d = DateTime.TryParseExact(dr["Date_"].ToString(), "dd/MM/yyyy", null, DateTimeStyles.None, out date) ? dtq : (DateTime?)null;
Upvotes: 1