×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

VFP OLE DB datetime data mismatch

VFP OLE DB datetime data mismatch

VFP OLE DB datetime data mismatch

(OP)
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 --> c#

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

RE: VFP OLE DB datetime data mismatch

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 Smileing

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.

RE: VFP OLE DB datetime data mismatch

(OP)
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

RE: VFP OLE DB datetime data mismatch

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 Smileing

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.

RE: VFP OLE DB datetime data mismatch

Griff could have a point. https://docs.microsoft.com/en-US/dotnet/api/system... 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
https://www.doschke.name

RE: VFP OLE DB datetime data mismatch

(OP)
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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close