如何使用vb.net在sql2005中仅插入当前时间 [英] how to insert only current time in sql2005 using vb.net

查看:67
本文介绍了如何使用vb.net在sql2005中仅插入当前时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

先生/妈妈

我想在数据库中插入当前时间,但是在时间字段中出现了一个错误.我不了解如何在数据库中插入时间,请帮忙.
以下是我的代码

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

推荐答案

System.DateTime.Now.ToString(("hh:mm:ss"))将给您当前时间.


dsNewRow.Item("intime") = System.DateTime.Now.ToString("HH:mm:ss tt") 'Gives it to you as a string.



问候



Regards,


这篇关于如何使用vb.net在sql2005中仅插入当前时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆