Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
354 views
in Technique[技术] by (71.8m points)

Date not saving in right format vb6.0, SQL server 2005

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")
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 & "')"

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...