Results 1 to 3 of 3

Thread: Help! urgent! How do u insert time into database

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2001
    Posts
    41

    Help! urgent! How do u insert time into database

    Help! urgent! How do u insert time into database
    here is my code : i'm getting errors in the database after a successfull insert: the database StartTime field is format is set to h\nn\ss AM/PM

    but when instead of inserting the time from Today.ToLongDateString

    it give me 12:00:00 AM and if u click on it it give u the defult date
    >.<

    i don't know what is wrong i just wanted Time in the data field and not stupid date thing cos if i fill from that database i get the date in the dataset instead of the defult time say 12:00:00 which the time is incorrect as well ><

    Me.OleDbConnection2.Open()

    'Insert into database

    Me.OleDbDataAdapter1.InsertCommand.Parameters("Date").Value = Today.ToShortDateString
    Me.OleDbDataAdapter1.InsertCommand.Parameters("StartTime").Value = Today.ToLongTimeString
    Me.OleDbDataAdapter1.InsertCommand.Parameters("FinishTime").Value = DateTime.Now


    Try
    ' Execute insert statement
    i = Me.OleDbDataAdapter1.InsertCommand.ExecuteNonQuery()

    'Catch any errors
    Catch OleDBError As System.Data.OleDb.OleDbException

    MsgBox("error is " + OleDBError.ToString)

    End Try

    OleDbConnection2.Close()

  2. #2
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474


    What brought me to this forum was that stupid bug.

    This is a problem in how DBDate datatype parameteres are parsed. To fix it go to the section of Wizard generated code and look at the Insert and Update commands of the dataadapter. You will see something like this:
    VB Code:
    1. Me.OleDbInsertCommand2.Parameters.Add(New System.Data.OleDb.OleDbParameter("tm", System.Data.OleDb.OleDbType.[b]DBDate[/b], 0, "tm"))
    Change any occurrence of DBDate or DBTime to Date or Time
    Then the code will be:
    VB Code:
    1. Me.OleDbInsertCommand2.Parameters.Add(New System.Data.OleDb.OleDbParameter("tm", System.Data.OleDb.OleDbType.[b]Date[/b], 0, "tm"))
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  3. #3
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    Alternatively you can avoid the wizard generated code and use commandbuilder.
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width