Type mismatch error inserting rows in DBF File RRS feed

  • Question

  • I'm trying to process some SQLite Databases and insert some data into DBF Files, DBase III (old databases, cannot exchange them for the moment) and I keep getting type mismatch error when trying to insert date values. Date column in DBF file is DATE(8,0)

    I can successfully connect to the DBF using

    OleDbConnection con2 = new OleDbConnection(@"Provider=VFPOLEDB.1;Data Source=C:

    I am creating a list of receipts

    receipt.date = rdr.GetDateTime(1); // ok here

    And here It always crashes

    OleDbCommand cmd2 = new OleDbCommand(query, con2); // used in previous query

    cmd2.CommandType = CommandType.Text; cmd2.CommandText = "INSERT INTO decont (cod, data)" + " VALUES (?, ?)"; cmd2.Parameters.AddWithValue("@cod", Convert.ToInt32(receipts[j].c_id)); cmd2.Parameters.AddWithValue("@data", receipts[j].date); // **


    ** - here I tried lots of Formatting and Parsing, even manual inserting using {date} {^date} in different formats with "-", "/"

    I have little experience, this is just a small project to make things easier in office.

    Any help would be appreciated. Thank you.

    Thursday, July 30, 2020 11:00 PM

All replies

  • Hi Alexandru Bodea,
    First, you need to check whether the data type of the field "date" is date or datetime.
    According to your description, the value of "receipts[j].date" may not be of type date or datetime.
    So you can try to use DateTime.TryParseExact method.

    DateTime dateDate=DateTime.ParseExact(receipts[j].date, "dd'/'MM'/'yyyy", null);

    Best Regards,
    Daniel Zhang

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, July 31, 2020 7:25 AM