由vb.net更新数据库中的日期字段 [英] update date field in database by vb.net

查看:141
本文介绍了由vb.net更新数据库中的日期字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,问题是当我更新表单时查询正常运行并更新其他字段但日期字段不会更新,它设置为最小值1847这样的东西。这是我的代码。

i am developing an app ,the problem is when i update a form the query runs properly and it update the other field but the date field wont update ,it set to its minimum value 1847 something like this. this is my code .

Dim dt As Date
                   dt = dtp_Expired.Value
                   sqlad.UpdateCommand = New SqlCommand(" UPDATE tbl_CustomerCard SET fld_custPhone = " & txt_Phone.Text & ", fld_ExpireDate = " & dt & " WHERE fld_CardNo = " & txt_MembershipID.Text & " ", sqlc)
                   Try
                       sqlad.UpdateCommand.ExecuteNonQuery()
                       MsgBox("Customer Data Update")
                   Catch ex As Exception
                       MsgBox(ex.Message)
                   End Try



请帮助我,我不知道我在哪里错误

日期值来自日期时间选择器,其结构如下:20/12/1991

谢谢你。


Please help me in this , id dont know where i mistake
the date value comes from a datetime picker and its formate is like : 20/12/1991
thank u .

推荐答案

使用参数化查询,如下所示:

Use parametrized query, like this one:
UPDATE tbl_CustomerCard SET fld_custPhone = @Phone, fld_ExpireDate = @Exdate WHERE fld_CardNo = @CardNo





然后使用 SQLParamterCollection [ ^ ] ://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.aspx> SQLCommand [ ^ ]。



进一步信息,请参阅:

如何:执行参数化查询 [ ^ ]

SqlParameterCollection。 AddWithValue方法 [ ^ ]



Then call it using SQLParamterCollection[^] for SQLCommand[^].

For further information, please see:
How to: Perform Parameterized Queries[^]
SqlParameterCollection.AddWithValue Method[^]


这篇关于由vb.net更新数据库中的日期字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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