Dear Experts.
I write windows application with "VS2010" that bind "SQLServer 2008".
I use "DataSource Wizard" to manipulate DataSet,BindingSource,TableAdapter,BindaingNavigator and also DataGridView.
I have a "Table" named Sample in my "Database".
A one of it's filed has "DateTime" datatype. the field's name is "Date".
I want to "Convert" data when "get" from database and also when "set" to database.
The convertion is from "datetime" to "persian datetime" and reverse.
I solve "getting" data convertion in DataGridView with "CellFormatting" event by this code:
private void StudentExamDataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (e.Value == DBNull.Value || e.Value == null)
return;
if (e.ColumnIndex < 0 || e.RowIndex < 0)
return;
if (e.ColumnIndex == StudentExamDataGridView.Columns["Date"].Index)
{
e.FormattingApplied = true;
e.Value = new PersianCalendarEx(Convert.ToDateTime(e.Value)).PersianDate;
}
}
it's work perfectly.
but problem is , when user input date in "persian format" (for example : 1391/12/21) this saved to database like that and no convertion occure.
I know how to convert persianDate to DateTime, but don't know where write it's code, that user entered persian date value on DatagridView and automatically convert to DateTime and save to dataset or datasource or table.
thanks for any help.