Not valid date, importing from csv to access

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sl1ver
    New Member
    • Mar 2009
    • 196

    Not valid date, importing from csv to access

    im importing text from a csv file to a access database
    i create my parameter
    Code:
    OleDbParameter Param7 = new OleDbParameter("@Param7", OleDbType.DBTimeStamp);
                            cmd.Parameters.Add(Param7);
    then i convert the read value to date time
    Code:
    cmd.Parameters["@Param7"].Value = Convert.ToDateTime(columns[6].Replace("\"", ""));
    it stops by the second piece of code i put in saying
    "String was not recognized as a valid DateTime"

    What am i doing wrong?
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    Doing everything in one line might seem clean, but it makes it hard to check assumptions as well as hard to catch exceptions.

    Instead of doing it all in one line, try breaking it down into a couple lines, so you can step through it and see where something is not as you expected.
    Code:
    cmd.Parameters["@Param7"].Value = Convert.ToDateTime(columns[6].Replace("\"", ""));
    Code:
    string newDateAsString = columns[6].Replace("\"", "");
    MessageBox.Show(newDateAsString, "Does this look like a date?");
    
    cmd.Parameters["@Param7"].Value = Convert.ToDateTime(newDateAsString);

    Comment

    Working...