Go Back   CodingForums.com > :: Server side development > ASP.NET

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-29-2010, 08:09 PM   PM User | #1
aktiv
New Coder

 
Join Date: Aug 2009
Location: Indiana
Posts: 37
Thanks: 11
Thanked 1 Time in 1 Post
aktiv is an unknown quantity at this point
Exclamation help inserting date into SQL DB

i have a form that collects the date an inserts it into sql db. The form has 3 text fields one for month, one day and one for year.

The problem is that when the date is being inserted into the database it is not inserting the proper values.

the sql code is below:

Code:
 strSql &= ", crsCity = '" & dbSafe(Request.Form("city")) & "', crsDate = " & (Request.Form("yr")) & "-" & (Request.Form("mo")) & "-" & (Request.Form("day")) & ""
If I choose the follow date on the form, 12/31/2010 it inserts the following into the DB, 5/22/1905
aktiv is offline   Reply With Quote
Old 10-29-2010, 11:06 PM   PM User | #2
aktiv
New Coder

 
Join Date: Aug 2009
Location: Indiana
Posts: 37
Thanks: 11
Thanked 1 Time in 1 Post
aktiv is an unknown quantity at this point
Resolved

ok, solved it... code is below:

Code:
crsDate = '" & (Request.Form("yr")) & "-" & (Request.Form("mo")) & "-" & (Request.Form("day")) & "'"
notice the single quotes they are bolded
aktiv is offline   Reply With Quote
Old 11-02-2010, 06:53 PM   PM User | #3
accwebworks
New Coder

 
Join Date: Mar 2010
Location: nyc
Posts: 31
Thanks: 0
Thanked 1 Time in 1 Post
accwebworks is an unknown quantity at this point
You really should be using SqlParameters to pass values with your queries.
If you dynamically append them you are vulnerable to sql injection attacks.
accwebworks is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:51 PM.


Advertisement
Log in to turn off these ads.