Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VFP OLE DB datetime data mismatch

Status
Not open for further replies.

Nro

Programmer
May 15, 2001
337
0
16
CA
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…

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
 
I would suspect, and it's a guess really, that the underlying field could be just a date , not a date time?

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
Hello Griff
Nope. In the VFP table, the field is DateTime.
In VFP, datime type seems to be less fussy than OLE DB because I can replace it with DATE() or DATETIME() function.

I assume that OleDbType.DBTimeStamp is the equivalent of VFP DateTime . Maybe I’m wrong but I’ve also tried OleDbType.Date with no success.

Thanks
 
Try passing it as a string and using a VFP function to change it to the correct format.

lcUPD = "UPDATE SysId" ;
lcUPD += " SET Sy_NextID = ?, Sy_Inst = ?, UsrNo = ?, LastUpd = CTOD( ? )";
lcUPD += " WHERE SysId.Sy_Table = 'tblTest'";


Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
Griff could have a point. at least points out this OleDbTtype is correct for DateTimes, but you might need to set the value to a string in the format yyyymmddhhmmss and not a C#.NET System.DateTime.Now value, so you have to bring it in OleDb Format and then the OleDB Provider will do the rest.

Bye, Olaf.

Olaf Doschke Software Engineering
 
I’m embarrassed.

The problem wasn’t with the DateTime (LastUpd) field, but with the char field (UsrNo). It was OleDbType.char instead of OleDbType.Decimal.

I think when you work too hard on a problem, you lose your focus.

Everything is working fine now.

Anyway, thanks for your help guys.
Nro
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top