如何在VB.Net中插入日期 [英] How to insert Date in VB.Net

查看:85
本文介绍了如何在VB.Net中插入日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

This is my query in sql server







INSERT INTO dbo.KaunselingDT (NoKaunselor, NoPerakuan, Date)VALUES('123', '456', '14 / Oktober / 2014')







And this is my Save() button in VB.Net







sql = "INSERT INTO dbo.KaunselingDT (NoKaunselor, NoPerakuan, Date)" _
                & "VALUES('" & Me.txtNoKaunsDaftar.Text & "', '" & Me.txtNoAkuanAmalan.Text & "', '" & Me.lblDate.Text & "')"







How to change the lblDate to smalldatetime data type?

推荐答案

改为使用SqlParameters。您的解决方案非常不安全,容易进行SQL注入。此外,当服务器不使用与客户端相同的日期格式时,我确保您收到错误。请查看以下文章并以正确的方式进行操作!



http:// vbnetsample。 blogspot.nl/2007/10/using-sqlparameter-class.html [ ^ ]



将SQLParameters与VB.NET / C#一起使用 [ ^ ]



祝你好运!
Use SqlParameters instead. Your solution is extremely unsafe and prone to sql-injection. Also, I ensure you to get errors when the server does not use the same date format as the client. Please check out the article below and do it the right way!

http://vbnetsample.blogspot.nl/2007/10/using-sqlparameter-class.html[^]

Using SQLParameters with VB.NET/C#[^]

Good luck!


Dim formatInfo As New DateTimeFormatInfo()
formatInfo.ShortDatePattern = "dd/MM/yyyy"
formatInfo.DateSeparator = "/"
Dim objDate As DateTime = Convert.ToDateTime(Me.lblDate.Text, formatInfo)</pre>


这篇关于如何在VB.Net中插入日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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