How to retrieve TimeSpan from typed DataSet?

Discussion in 'Microsoft ADO .NET' started by deko, Mar 7, 2006.

  1. deko

    deko Guest

    I keep getting an InvalidCast exception when trying to do this:

    DataRow row = dtP.Rows.Find(projectID);
    bakInterval = new TimeSpan();
    bakInterval = (TimeSpan)row[colBI]; //colBI is a string const

    Error Message: "Specified cast is not valid".

    As far as I know, the rowBI column is in fact a TimeSpan. Below is how the
    dtP table is created. The last line shows colBI created as a TimeSpan type.

    DataTable tblProject = database.Tables.Add("TableProject");
    DataColumn project_ID = tblProject.Columns.Add("Project_ID",
    typeof(Int32));
    project_ID.AllowDBNull = false;
    project_ID.Unique = true;
    project_ID.AutoIncrement = true;
    project_ID.AutoIncrementSeed = 1;
    project_ID.AutoIncrementStep = 1;
    tblProject.PrimaryKey = new DataColumn[] { tblProject.Columns[0] };
    tblProject.Columns.Add("ProjectName", typeof(string));
    tblProject.Columns.Add("BackupInterval", typeof(TimeSpan));

    I can cast ProjectName to a string, and Project_ID to an int, but I can't
    cast BackupInterval to a TimeSpan.

    What am I doing wrong?

    Thanks in advance.
     
    deko, Mar 7, 2006
    #1
    1. Advertisements

  2. deko

    deko Guest

    I figured it out... had to do with out parameters
     
    deko, Mar 7, 2006
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paddy

    GetChanges in a Typed Dataset returns a DataSet??

    Paddy, Jul 3, 2003, in forum: Microsoft ADO .NET
    Replies:
    1
    Views:
    2,758
    Gavin Joyce
    Jul 5, 2003
  2. Petter L

    create a Dataset Column in int32 or timespan?

    Petter L, Jun 14, 2004, in forum: Microsoft ADO .NET
    Replies:
    4
    Views:
    559
    Petter L
    Jun 15, 2004
  3. Brad Allison

    typed vs strong typed dataset

    Brad Allison, Jul 21, 2004, in forum: Microsoft ADO .NET
    Replies:
    3
    Views:
    691
    Brad Allison
    Jul 21, 2004
  4. Guest
    Replies:
    2
    Views:
    521
    Guest
    Mar 7, 2005
  5. A.M-SG
    Replies:
    6
    Views:
    1,486
    Steven Cheng[MSFT]
    Feb 1, 2006
Loading...

Share This Page