Trying to insert a Date(without Time) into a .DBF(Visual Fox Pro Database) with C#

2.1k views Asked by At

like the title explains im trying to insert a Date into a .DBF file. I get always a "Type Mismatch"... i tried almost everything by now... :( So this is my Command:

"INSERT INTO VARTXTSZ(herst_nr, var_art, var_schl, var_txt, var_bild, var_stat, var_kmt, d_textur, lief_ab, lief_bis, textur_kch, maskierung, rgb_r, rgb_g, rgb_b, transp, glanz, std_gr_lag)"
            + "VALUES(" + herstNr + ", " + ausfGrp + ", '" + ausfSchl + "', '" + ausfTxt + "', ''      , 0, '', '', 250319900, 250319900, 0, 0, 0, 0, 0, 0, 0, 0)";

The "lief_bis" and "lief_ab" column given me some hard time... if anybody knows how the data should look like when its inserted, please leave a line!

I used a DBF-Viewer to take a look inside the Database, the data in these columns are formatted like that: "25.03.1990" i tried this too but with no results.

And this is not for any product, its just for testing. So security-issues are known and not relevant.

Big thx in advance!:)

1

There are 1 answers

0
Dhugalmac On BEST ANSWER

I'm trying to insert a Date into a .DBF file.
the data in these columns are formatted like that: "25.03.1990"

Let's start by trying to determine the ACTUAL Field type for "lief_bis" and "lief_ab" - they could be DATETIME, DATE, or CHARACTER Field Types.

From the value you are reporting to have seen in the DBF-Viewer, it is very likely that these fields are Not REALLY DATE fields.
From the appearance of the data it looks like they are Character fields, but how a Date APPEARS may be set by some of the environment settings.

IF the data fields are REALLY DATE fields then your INSERT command needs to look something like the following:

* --- for a Date of  01/03/2020 ---
INSERT INTO temp2 (Date1) VALUES ({^2020-03-01})  

If you still get a Data Type Mismatch error, then those fields are not DATE fields and you need to do some more 'homework' to come back with what they REALLY are.

Good Luck