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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I cant insert a DateTime in a FreeTable from C# using oleDB

Status
Not open for further replies.

Wolfen12

Programmer
Jul 17, 2007
19
NL
Hi

Yes its me again with my freetable questions.
Sorry that I use this forum for C# questions, but help here are really sufficient and fast.Thanks everyone.

Im trying to insert a Date in a DateTime Field in a FreeTable using C#, but I get an error "Data Type mismatch".

Does anyone know how to convert this DateTime so that the FreeTable will accept it or is it an oleDB problem:
INSERT INTO table(CurrentDateandTime)VALUES(DateTime.Now)

Thanks
 
Hi again Wolfen,

This looks like a similar problem to the one you had before. Basically, you need to convert your datetime string to an actual datetime value.

One way to that would be something like this:

Code:
INSERT INTO table (CurrentDateandTime) 
  VALUES(DATETIME(2006, 10, 10, 12, 0, 0))

(Note that the above is one line. I wrapped it to two lines for readability.)

You can also use the CTOT() function, which converts a character string to a datetime, but that would involve worrying about the date format settings.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Hi

Thank you so so much.
I did find a solution, before I read your last post.
I have to say, it helps - because now I know 2 ways of doing it.I treied and it worked.For interest sake here is the other solution.
Maybe you can comment on this, you always helping me I learn alot, hope you dont know this, then I'll feel better teaching you something;-)

INSERT INTO myTable(datefiels)VALUES(?)
OleDbParameter parm1 = new System.Data.OleDb.OleDbParameter();
parm1.Value = DateTime.Now; this.oleDbDataAdapter1.InsertCommand.Parameters.Add(parm1);
 
Yes, you'll be pleased to know that I didn't know about OleDb.OleDbParameter() <g>.

But now I see how it works, and why it would be a good approach. I guess this mechanism will take care of the data type conversion for you, which reduces your need to know Foxpro-specific syntax.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Hi

Thanks Mike, I feel so glad I also could give advise.Ha ha.
Now I'm struggling again with the Logical DataType.Looks like a FreeTable saves it as a T or a F.I think this is now a big problem, case with the DateTim was easer, cause the format stays the same, but C# see a value as 1 or 0 and true or false, but not as F or T.You cant force in a string set to "F" or "T".Any ideas anyone???
 
This shouldn't be a problem. You don't need to force the value to a string. Just wrap the T or F in dots (periods). For example:

Code:
INSERT INTO MyTable 
  (MyLogicalField) VALUES ([b].[/b]T[b].[/b])

If you prefer to use your OleDb.OleDbParameter() method, then you should be able simply to pass 0 or 1.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top