Click here to Skip to main content
15,893,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Respected sir/mam

I want to insert current time in my database but there is accrued a error at time field. I dnt understand how to insert time in database pls help me.
following is my code

 Try

            Dim cb As New OdbcCommandBuilder(da)
            Dim dsNewRow As DataRow

            dsNewRow = ds.Tables("Add").NewRow()

            dsNewRow.Item("id") = no
            dsNewRow.Item("vehicleNo") = txtlVin.Text
            dsNewRow.Item("challanNo") = txtlChno.Text
            dsNewRow.Item("itemName") = txtlItmNm.Text
            dsNewRow.Item("quantity") = txtlQty.Text
            dsNewRow.Item("CustName") = txtlCustNm.Text
            dsNewRow.Item("site") = txtlSite.Text
            dsNewRow.Item("indate") = System.DateTime.Now.ToString((" yyyy-MM-dd")) 'Date.Today

            dsNewRow.Item("intime") = TimeOfDay

            dsNewRow.Item("intype") = "LOAD"
            dsNewRow.Item("inout") = "IN"

            ds.Tables("Add").Rows.Add(dsNewRow)
            da.Update(ds, "Add")

            MsgBox("New Record added to the Database")
        Catch ex As Exception
            MsgBox(ex.ToString)
        Finally
            cn.Close()
            da.Dispose()
            ds.Dispose()
        End Try





thank u in advance
Posted
Updated 8-Jan-12 19:05pm
v2

System.DateTime.Now.ToString(("hh:mm:ss")) will give you the current time.
 
Share this answer
 
v2
C#
dsNewRow.Item("intime") = System.DateTime.Now.ToString("HH:mm:ss tt") 'Gives it to you as a string.


Regards,
 
Share this answer
 
v2
Comments
Avi Mali 9-Jan-12 1:09am    
Thank u for your valuation suggestion.
Al Moje 9-Jan-12 1:37am    
Welcome...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900