IBM Computer, Laptops and Servers

Back Homepage Content Directory Resource Guide Blog

Passing Dates to a Stored Procedure

Pari writes "I take a date from the html form and wish to pass on to the stored procedure where the value is inserted . . .
Pari writes "I take a date from the html form and wish to pass on to the stored procedure where the value is inserted. This is the stmt i give in the asp page:
----------------------------------------
conn.execute ("InsertMain 'id','name','desc','syno','ldate'")

The stored proc is:
---------------------
CREATE PROCEDURE [InsertMain]
@topid varchar(20),
@name varchar(50),
@descr varchar(200),
@syno varchar(150),
@live datetime
AS
Insert into MainTopic(topic_id,Topic_name,description,synopsis,livedate) values(@topid,@name,@descr,@syno,@live)

I get the following error:
-----------------------------
Microsoft OLE DB Provider for ODBC Drivers error '80040e07'

[Microsoft][ODBC SQL Server Driver][SQL Server]Error converting data type varchar to datetime.

PUHLEAZE help me... if this doesnt work i have to work with inline sql stmts which work.... thnx in adv. pari"


SQL Server is pretty pick about dates (and so am I :). Bascially if you get the format just a little bit wrong you will get this type of error. You can find a list of valid date formats in Books Online under the CONVERT statement.

My suggestion would be to pass the date into the parameter a character string and explicitly convert it do a date field. Make @LIVE a VARCHAR(40) field. Then add the following lines:

DECLARE @livedate DATETIME
SELECT @livedate=CONVERT(datetime, @live)
IF @ERROR 0 THEN
/* Do some error processing */
ELSE
/* Do the insert using @livedate*/

This will explicitly convert from VARCHAR to DATETIME. If there is an error you can trap it and return an appropriate error message. Again, look at the list of valid dates in Books Online and stick with one of those formats and you should be ok.

[ Comment, Edit or Article Submission ]

Share this:

Add To Yahoo MyWeb Add To Google Bookmarks Add To Furl Fav This With Technorati Add To Newsvine Add To Bloglines Add To Ask Add To Windows Live Add To Slashdot Stumble This Digg This Add To Del.icio.us Add To Reddit

More about:

Oct November 2008 Dec
Sun Mon Tue Wed Thu Fri Sat
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30            

IBM Computer, Laptops and Servers Blog on Technorati Related Blog of IBM Computer, Laptops and Servers on Sphere
Content Directory
Resource Guide


EDGE Tech Corporation

Website Links
IBM Computer, Laptops and Servers Copyright © 2008 www.ibmfans.com. All rights reserved. Site Map
Homepage | Blog | Advertise | Privacy Policy | Disclaimer | Contact Us | Links