Insert DateTime value in SQL-server

Hi experts,

probably an easy one...

A db on sql-server (2000),
has a table 'tbl_ResTest' with a datetime field (fldResDate)

Using a stored procedure:
'*********
CREATE PROCEDURE [dbo].[sp_DocNumAddDoc]
@dtResDate DateTime
AS

Insert into tbl_ResTest
(fldResDate)

Values

(@dtResDate)

GO

'*************

'**********************
In VB :
strSQL = "Execute sp_DocNumAddDoc " _
& "#" & CDate(txtResDate.Text) & "#"

objConn.Execute (strSQL)

'**********************


The date entered in the textbox 'txtResDate' looks like: 12/03/2003

On executing it errors out with "[Microsoft][ODBC SQL Server Driver][SQL Server]Line 1 : Incorrect syntax near '/'."


In what format should the date be?
(the example shown is just what it is, an example ;-) )
G's
Ricky
LVL 12
PaurthsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TimCotteeHead of Software ServicesCommented:
Hi Paurths,

I would always use this:

strSQL = "Execute sp_DocNumAddDoc " _
& "'" & Format(txtResDate.Text,"yyyy-mm-dd") & "'"

This ensures that the date is in a format that is unambiguous to SQL server and also is correctly surrounded in ' characters rather than # which is usually used with access (which I know you are familiar with!).

Tim Cottee MCSD, MCDBA, CPIM
http://www.timcottee.tk 

Brainbench MVP for Visual Basic
http://www.brainbench.com

Experts-Exchange Advisory Board Member
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PaurthsAuthor Commented:
Hi Tim,

thanx for the quick response.

Now it errors out with "Error converting data type varchar to datetime"

G's
Ricky
0
PaurthsAuthor Commented:
solved now, Tim.

I was still accepting dtResDate as datetime,
changed that to varchar and it works now.

Thanx for your assistance
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

darkolausCommented:
Hey TimCotte, you posted in

http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20287510.html

code for taskstuff in win9x, i really need it for winnt. Hope you'll see this.

Greetz, Sven
0
TimCotteeHead of Software ServicesCommented:
darkolaus:

have a look at the code posted by eddykt in http://www.experts-exchange.com/Q_20555955.html

It contains an example which works for NT (based on some code I have submitted here before.)
0
darkolausCommented:
thnx alot
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.