Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Problem with inserting date value into MSSQL

Reply
Thread Tools

Problem with inserting date value into MSSQL

 
 
Igal
Guest
Posts: n/a
 
      11-19-2006
I'm trying to insert a date value into MSSQL, the type of the sql filed
is: "smalldatetime"
and i'm trying to insert a text Variable that looks like this:
"19/02/2006".

.... SET update_date='" & Update_Date & "' ...

i get the message:

The conversion of char data type to smalldatetime data type resulted in
an out-of-range smalldatetime value

 
Reply With Quote
 
 
 
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      11-19-2006
Igal wrote:
> I'm trying to insert a date value into MSSQL, the type of the sql
> filed is: "smalldatetime"
> and i'm trying to insert a text Variable that looks like this:
> "19/02/2006".
>
> ... SET update_date='" & Update_Date & "' ...
>
> i get the message:
>
> The conversion of char data type to smalldatetime data type resulted
> in an out-of-range smalldatetime value


Always use a universally standard format for supplying dates to a database.
The ISO standard, YYYYMMDD works very well. Here are a couple articles about
handling dates:
http://www.aspfaq.com/show.asp?id=2313
http://www.aspfaq.com/show.asp?id=2040
http://www.aspfaq.com/show.asp?id=2260


Further points to consider:
Your use of dynamic sql is leaving you vulnerable to hackers using sql
injection:
http://mvp.unixwiz.net/techtips/sql-injection.html
http://www.sqlsecurity.com/DesktopDefault.aspx?tabid=23

See here for a better, more secure way to execute your queries by using
parameter markers:
http://groups-beta.google.com/group/...e36562fee7804e

Personally, I prefer using stored procedures.
http://groups.google.com/group/micro...9dc1701?hl=en&

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


 
Reply With Quote
 
 
 
 
Igal
Guest
Posts: n/a
 
      11-20-2006
in the end i used a functions that converts the date to SQL format
(YYYY/MM/DD)
and that worked fine.
but for this application nothing much u can do, it's very old code, and
i'm trying some how to polish, i'm php programmer, not asp actually
will prolly write a new one in time for the whole system.

this article is very interesting and helpful. thanks for the
information.
> http://mvp.unixwiz.net/techtips/sql-injection.html


 
Reply With Quote
 
 
 
Reply

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Inserting into DB table with date from Generic List =?Utf-8?B?U3Jpbmk=?= ASP .Net 0 11-07-2006 04:33 AM
Date value set to current datetime, after recall the date value is null moonhk Java 5 10-11-2006 04:45 AM
Date, date date date.... Peter Grison Java 10 05-30-2004 01:20 PM
Mssql image into MemoryStream code not working... Chris Bond ASP .Net 0 04-23-2004 07:41 AM
DBI problem inserting html into mssql db Kristian Perl 0 11-13-2003 12:23 PM



Advertisments