Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert Date into SQL

Status
Not open for further replies.

Pamy

MIS
Oct 15, 2002
29
0
0
SG
Hi
I'm trying to insert date from a form input to SQL..

This is how i wrote the code

txtDateValue = Request.Form("datevalue")

sql = "INSERT INTO tbTopic(Topic,TopicDesc,TopicDetail,[Date],Venue,[Time],MaxAllowed) values('?','?','?',""'#" & txtDateValue & "#'"",'?','?','?')"
sql = Replace(sql, "?", txtTopic, 1, 1)
sql = Replace(sql, "?", txtTopicBrief, 1, 1)
sql = Replace(sql, "?", txtTopicDetail, 1, 1)
sql = Replace(sql, "?", txtVenue, 1, 1)
sql = Replace(sql, "?", txtTimeValue, 1, 1)
sql = Replace(sql, "?", txtMaxAllowed, 1, 1)



This is error generated from the above code

Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC SQL Server Driver][SQL Server]The name ''#10/03/2003#'' is not permitted in this context. Only constants, expressions, or variables allowed here. Column names are not permitted.


Any idea where I may be going wrong?

Your help is greatly appreciated!
 
You can remove a set of double quotes and the # signs around the date. Depending on settings, the double quotes around the date value tell SQL Server that the string is an identifier. But it doesn't follow the rules for an identifier and causes the syntax error. SQL Server doesn;t require teh # as a date delimiter. It uses a single quote.

The follwoing should work.

sql = "INSERT INTO tbTopic(Topic,TopicDesc,TopicDetail,[Date],Venue,[Time],MaxAllowed)
values('?','?','?','" & txtDateValue & "','?','?','?')"
If you want to get the best answer for your question read faq183-874 and faq183-3179.
Terry L. Broadbent - DBA
SQL Server Page:
 
hi,
What if the data types for the date is Datetime? How should the code be like?
 
Thks..
I think i got the solution for converting string to date
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top