Hi,
> Thank you all for replying.
> I was able to get the select query to work like that:
>
> strDateSearch = "#" + dt.Month.ToString() + "/"
> + dt.Day.ToString() + "/" +
> dt.Year.ToString() + "#";
That might solve your problem, but it's not the best solution, use a
Parameterized query instead
> But I also want to update the Date fields in the mdb file.
> And when I do so with:
[quoted text clipped - 10 lines]
> I will take a look at OleDbParameter later today.
> Thank you for your time.
What error you are getting?
jr1024 - 11 Jul 2007 07:48 GMT
On Jul 10, 5:21 pm, "Ignacio Machin \( .NET/ C# MVP \)" <machin TA
laceupsolutions.com> wrote:
> > But I also want to update the Date fields in the mdb file.
> > And when I do so with:
[quoted text clipped - 12 lines]
>
> 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?
Ignacio Machin ( .NET/ C# MVP ) - 11 Jul 2007 15:27 GMT
Hi,
What if you write the code like "UPDATE TableName SET [Date]=@p1 WHERE
ID=@p2";
I do not remember if DATE is a reserved word
> On Jul 10, 5:21 pm, "Ignacio Machin \( .NET/ C# MVP \)" <machin TA
> laceupsolutions.com> wrote:
[quoted text clipped - 66 lines]
>
> What am I doing wrong?