System.InvalidCastException: Specified cast is not valid.

2 posts, 0 answers
  1. GV
    GV avatar
    3 posts
    Member since:
    Nov 2009

    Posted 18 Nov 2009 Link to this post

    When I add it to DATABASE I do following

    Dim

     

    wwctetime1 As Date

    wwctetime1=RadDateTimePicker1.Text

    cmd.Parameters.Add(

    "@wtime1", SqlDbType.Int).Value = Hour(wwctetime1)

    Now I want to read from Database and Assigen value back to RadDateTimePicker1

    So how I want to do is

     

     

    RadDateTimePicker1.SelectedDate = dta.Rows(0)(

    "wwctetime1")


    In my data base I'm just saving time ex 2, 7, 23,22 etc

     I would really appreciate any help

     

     

     

     

     

     

     

     

     

     

  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 19 Nov 2009 Link to this post

    Hello,

    I suppose your database value return int value. Try the following code to set the selected date:
    vb:
    Dim dt As DateTime = DateTime.Now.[Date
    dt = dt.AddHours(dta.Rows(0)("wwctetime1")) 
    RadDateTimePicker1.SelectedDate = Convert.ToDateTime(dt)  

    Thanks
    Princy.
Back to Top