|
-
May 15th, 2003, 12:05 AM
#1
Thread Starter
Member
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()
-
May 15th, 2003, 04:52 AM
#2
Frenzied Member
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:
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:
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
-
May 15th, 2003, 04:53 AM
#3
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|