I want to create an expression-based column in DataSet that can do some manipulation on another DateTime column. Specifically, I have a database column named DateEnrolled. I want to create a column called ExpectedGraduationDate, which is equal to DateEnrolled + 180 (days).
I have tried to put in the Expression property of the ExpectedGraduationDate the following:
1. DateEnrolled + 180 // did not work
2. DateEnrolled.Add(180) // did not work either
Does ADO.NET expression-based columns support SQL date manipulation functions? Is there any way to work around that issue?
Loading
DavidPosted Jul 22, 2007, 6:07 AM
private void button1_Click(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("key");
dt.Columns.Add("DateEnrolled", Type.GetType("System.DateTime"));
dt.Columns.Add("ExpectedGraduationDate", Type.GetType("System.DateTime"));
dt.ColumnChanged +=new DataColumnChangeEventHandler(dt_ColumnChanged);
// of course this isn't the ideal place to define the event handler!
DataRow dr = dt.NewRow();
dr[0] = "1";
dr[1] = DateTime.Now;
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[0] = "2";
dr[1] = new DateTime(2007, 1, 1);
dt.Rows.Add(dr);
dataGridView1.DataSource = dt;
}
private static void dt_ColumnChanged(object sender, DataColumnChangeEventArgs e)
{
if (e.Column.ColumnName == "DateEnrolled")
{
DateTime dateEnrolled = (DateTime)e.Row["DateEnrolled"];
e.Row["ExpectedGraduationDate"] = dateEnrolled.AddDays(180);
}