我试图在 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!