problem updating Access database with values from formatted cell

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,
I have a DataGridView with a textbox column which is bound at design time to
a DateTime field from a database.
Also at design time I set the Format value of this CellStyle like "yyyy", so
that I only get the year displayed.
How can I write only the year in the textbox and push a newly
generated DateTime variable back to database? (like DateTime dt = new
DateTime(int.Parse(e.Value.ToString()), 12, 12);). Everything that I tried
resulted in an exception in PushFormattedValue (at the bottom).
Currently the code that handles cell parsing is:
if (dataGridView1.Columns[e.ColumnIndex].Name == "DateYear")
{
DateTime dt = new DateTime(int.Parse(e.Value.ToString()), 12, 12);
string s_Date = dt.ToShortDateString();
dataGridView1.CurrentCell.Style.Format = null;
e.Value = s_Date;
MessageBox.Show(e.Value.ToString()); (here it shows a normal string
like 12/12/2005 which if it is inserted like this it doesn't generate any
error!)
e.ParsingApplied = true;
}
even if this executes ok I still get the data error to fire... Any ideas?
 
Back
Top