none
How to add OleDbType.Date to other DataTable in c#? RRS feed

  • Question

  • Hi!
    I have problem in converting OleDbType.Date to DateTime.

    I want to read from .dbf file and put some of the columns in other DataTable.
    So i am preparing table with special columns. Everything works fine except date.

    When i make a normal datetime column i receive error that i can not put int32 into DateTime ( it is ok because it's number of days since 1899 )

    dColYuma = new DataColumn("do_datawst", Type.GetType("System.DateTime"));



    And when i am preparing this:

    dColYuma =

    new DataColumn("do_datawst", Type.GetType("System.OleDbType.Date"));

    Then i have such error:
    "'data Type' argument cannot be null. Parameter name: dataType"

    Can anyone help me?
    I can't find any results to convert one date to another..
    When i read it i can add parameter that will convert for me DateTime to OleDbType, but it is only in CommandTxt from connection..

    Thank you for advise.

    Monday, August 17, 2009 11:35 AM

Answers

  • Well i made mistake by writing the code.

    It works fine when you declare the new column with DateTime Type
    dColYuma = new DataColumn("do_datawst", Type.GetType("System.DateTime"));



    and then just ...

    foreach

     

    (DataRow rzad in dtDokument.Rows)

    {

     

    DataRow row;

    row = tbYuma.NewRow();

    row[

    "do_datawst"] = rzad["do_datawst"];

    tbYuma.Rows.Add(row);
    }

    And it works fine!

    Monday, August 17, 2009 12:10 PM