On Jul 10, 5:21 pm, "Ignacio Machin \( .NET/ C# MVP \)" <machin TA
laceupsolutions.comwrote:
But I also want to update the Date fields in the mdb file.
And when I do so with:
OleDbDataAdapter da = ...;
DataSet ds = new DataSet();
da.Fill(ds, "TableName");
//...
da.Update(ds, "TableName");
I get Update syntax error. The same code updates string and number
fields no problem.
I will take a look at OleDbParameter later today.
Thank you for your time.
What error you are getting?
I get unhandled exception: "Syntax error in UPDATE statement"
And I get same error even when I try do it like that:
private void dataGrid_CellEndEdit(object sender,
DataGridViewCellEventArgs e)
{
DataGridViewCell theCell = dataGrid[e.ColumnIndex,
e.RowIndex];
DataGridViewCell ID_Cell = dataGrid[e.ColumnIndex-1,
e.RowIndex];
if (theCell.ValueType == typeof(DateTime))
{
if (conn != null)
conn.Close();
conn = new OleDbConnection(strConn);
DateTime dt = (DateTime)theCell.Value;
string updateQ = "UPDATE TableName SET Date=@p1 WHERE
ID=@p2";
conn.Open();
OleDbCommand cmd = conn.CreateCommand();
cmd.CommandText = updateQ;
OleDbParameter p1 = new OleDbParameter("@p1",
OleDbType.DBDate);
p1.Value = dt; //dt.ToOADate();
cmd.Parameters.Add(p1);
OleDbParameter p2 = new OleDbParameter("@p2",
OleDbType.Integer);
p2.Value = ID_Cell.Value;
cmd.Parameters.Add(p2);
try
{
cmd.ExecuteNonQuery();
}
catch(System.InvalidOperationException ex)
{
MessageBox.Show(ex.Message, "zzz Invalid Operation
Exception");
}
}
What am I doing wrong?