My problem is very simple, but it involves the VFP OLE DB driver. I have a free table with a datetime field called LASTUPD (timestamp for the last modification).
I’m accessing and updating this table with C# and the VS OleDbParameter. For any field other type (decimal, char, …) it’s working fine, but for datetime, I tried System.DateTime.Now but I always received “data type mismatch”
Here some code…
Any suggestions?
Thanks in advance.
Nro
I’m accessing and updating this table with C# and the VS OleDbParameter. For any field other type (decimal, char, …) it’s working fine, but for datetime, I tried System.DateTime.Now but I always received “data type mismatch”
Here some code…
Code:
OleDbDataAdapter loDataAdaptor = new OleDbDataAdapter();
lnCode = 123 ;
lcUsrNo = "123456" ;
lcUPD = "UPDATE SysId" ;
lcUPD += " SET Sy_NextID = ?, Sy_Inst = ?, UsrNo = ?, LastUpd = ?";
lcUPD += " WHERE SysId.Sy_Table = 'tblTest'";
// note that ? parameters are positional parameters, hence add the parameters
// in the correct order of appearance in the SQL statement above...
using (OleDbCommand loSysIdCMD = new OleDbCommand(lcUPD, toConnect))
{
loSysIdCMD.Parameters.Add(new OleDbParameter("Sy_NextID",OleDbType.Integer,0, "Sy_NextID"));
loSysIdCMD.Parameters.Add(new OleDbParameter("Sy_Inst", OleDbType.Integer, 0, "Sy_Inst"));
loSysIdCMD.Parameters.Add(new OleDbParameter("UsrNo", OleDbType.Decimal, 0, "UsrNo"));
loSysIdCMD.Parameters.Add(new OleDbParameter("LastUpd", OleDbType.DBTimeStamp, 0, "LastUpd"));
// Populate the parameters
loDataAdaptor.UpdateCommand = loSysIdCMD;
loDataAdaptor.UpdateCommand.Parameters["Sy_NextID"].Value = lnCode;
loDataAdaptor.UpdateCommand.Parameters["Sy_Inst"].Value = lnCode;
loDataAdaptor.UpdateCommand.Parameters["UsrNo"].Value = Decimal.Parse(lcUsrNo);
// Data type mismatch ...
loDataAdaptor.UpdateCommand.Parameters["LastUpd"].Value = System.DateTime.Now;
// Pousse les modifications
loDataAdaptor.UpdateCommand.ExecuteNonQuery();
}
Any suggestions?
Thanks in advance.
Nro