日期未以正确格式保存 vb6.0、SQL Server 2005 [英] Date not saving in right format vb6.0, SQL server 2005

查看:47
本文介绍了日期未以正确格式保存 vb6.0、SQL Server 2005的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在 sql server 2005 中保存这个日期格式,我得到的只是 1/1/1900 12:00:00 AM代码是

I am trying to save this Date format in sql server 2005, all i get is 1/1/1900 12:00:00 AM the code is

 txtRent_Date.Text = Format(Now, "mm/dd/yyyy")

推荐答案

您需要在日期周围加上撇号,如下所示:

You need to put apostrophes around your dates, like this:

strsql = "INSERT INTO Rental_Copies(Rental_id,Copies_id,Rent_Date,Due_Date)" & _
         "Values(" & txtID.Text & "," & ListView1.ListItems(X + 1) & ",'" & _
         txtRent_Date.Text & "','" & txtDue_Date.Text & "')"

正如其他人所说,您应该在使用数据之前验证数据并参数化您的 SQL 以防止 SQL 注入.

Like others have said, you should be validating your data before using it and parameterizing your SQL to prevent SQL injection.

这篇关于日期未以正确格式保存 vb6.0、SQL Server 2005的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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