J
jr1024
I am trying to update a Date field in mdb file, but I get "Update
syntax error" at run-time
This is my code:
private void dataGrid_CellEndEdit(object sender,
DataGridViewCellEventArgs e)
{
DataGridViewCell theCell = dataGrid[e.ColumnIndex,
e.RowIndex];
//get the ID cell
DataGridViewCell ID_Cell = dataGrid[e.ColumnIndex-1,
e.RowIndex];
DateTime dt = (DateTime)theCell.Value;
string strDate = "#" + dt.Month.ToString() + "/"
+ dt.Day.ToString() + "/"
+ dt.Year.ToString() + "#";
string updateQ = "UPDATE TableName SET Date=" + strDate
+ "WHERE ID=" + ID_Cell.Value ;
cmd = conn.CreateCommand();
cmd.CommandText = updateQ;
cmd.Connection.ConnectionString = strConn;
cmd.Connection.Open();
cmd.ExecuteNonQuery();
}
syntax error" at run-time
This is my code:
private void dataGrid_CellEndEdit(object sender,
DataGridViewCellEventArgs e)
{
DataGridViewCell theCell = dataGrid[e.ColumnIndex,
e.RowIndex];
//get the ID cell
DataGridViewCell ID_Cell = dataGrid[e.ColumnIndex-1,
e.RowIndex];
DateTime dt = (DateTime)theCell.Value;
string strDate = "#" + dt.Month.ToString() + "/"
+ dt.Day.ToString() + "/"
+ dt.Year.ToString() + "#";
string updateQ = "UPDATE TableName SET Date=" + strDate
+ "WHERE ID=" + ID_Cell.Value ;
cmd = conn.CreateCommand();
cmd.CommandText = updateQ;
cmd.Connection.ConnectionString = strConn;
cmd.Connection.Open();
cmd.ExecuteNonQuery();
}