Question

sql insert of date/time object returns oledb error code

Asked by: istomtom

I'm simply trying to insert a date/time object i've created with CreateODBCDate and insert it into a database. The access db is connected via OLEDB and the field is defined correctly as date/time.

This is the code I use to create the date object.

<CFSET myadissue = #ParseDateTime(#FORM.adIssue#)#>
<CFSET adissue_final = #CreateODBCDate(myadissue)#>

When output with cfoutput this displays {d '2003-04-08'} however when trying to insert it into the db the CFQUERY tag returns an error:

OLEDB Error Code = -524553244
Malformed GUID. in query expression '{d '2003-04-08'}'.

This is the CFQUERY code:
INSERT INTO Ads(adIssue)
VALUES(#adissue_final#)

Thanks guys!

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2003-04-08 at 17:40:52ID20579034
Tags

sql

Topic

ColdFusion Application Server

Participating Experts
7
Points
150
Comments
20

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Cfquery within a Cfoutput
    I have a problem creating a menu page. What happens is the user selects a reports and from a table the report is generated. Each field that makes the report can contain a list, and the list has to be generated from SQL. The first part works fine, getting the lists and assig...
  2. OLEDB and CF 4.5
    I am fairly experienced with CF, but I am having a weird problem. I want to execute a stored procedure using the OLEDB connection I have created for the application. I continue to receive the following error when I attempt to call a stored procedure which just does a simple...
  3. OLEDB Problem
    Hi Experts, I have a problem with OLEDB Connection. I have a MSACCESS Table with 200 fields when i select a recordset using OLEDB it takes nearly 10 seconds fetch records. Whereas it works good with ODBC. My project is already built on OLEDB so I could not change now. Y...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: entrance2002Posted on 2003-04-08 at 18:51:27ID: 8296399

How about this code?

INSERT INTO Ads(adIssue)
VALUES(#DateFormat(Now(),"mm/dd/yyyy")# #TimeFormat(Now(),"HH:MM:SS")#)

Try to run this one.

GOODLUCK!

Entrance2002 :)

 

by: entrance2002Posted on 2003-04-08 at 18:55:42ID: 8296416

If it works then you can have it this way:

INSERT INTO Ads(adIssue)
VALUES((#DateFormat(adIssue_final(),"mm/dd/yyyy")#)

That if you are only referring for a date.

Best wishes...

 

by: dash420Posted on 2003-04-08 at 20:54:24ID: 8296916

Try This

<cfquery datasource="dsn">
   INSERT INTO Ads(adIssue)
   VALUES( '#DateFormat(FORM.adIssue,"mm/dd/yyyy")#' )
</cfquery>

 

by: anandkpPosted on 2003-04-08 at 21:48:20ID: 8297137

get rid of the single quotes in ur query '{d '2003-04-08'}'

PS : DONT use these statements
<CFSET myadissue = #ParseDateTime(#FORM.adIssue#)#>
<CFSET adissue_final = #CreateODBCDate(myadissue)#>

just call teh query like :
INSERT INTO Ads(adIssue) VALUES(#CreateODBCDateTime(adIssue)#)

let me know

K'Rgds
Anand

 

by: hartPosted on 2003-04-08 at 22:33:43ID: 8297311

use Anands solution..

Regards
Hart

 

by: TallerMikePosted on 2003-04-09 at 06:54:45ID: 8299682

This may be silly talk, I don't know. But I don't know if you can use CreateODBCDate with SQL. (You don't want CreateODBCDateTime unless your field needs a time).

Anyhow, I remember something in Access where you needed to surround the dates in pound signs like so for some reason:

INSERT INTO Ads(adIssue)
VALUES(#4/8/2003#)

Anyhow, if this is the case, then you'll need to use DateFormat to sent the date. Maybe you won't even need the pounds signs? But for some reason I think that Access likes them. So try something like this:

INSERT INTO Ads(adIssue)
VALUES(###DateFormat(myadissue,"MM/DD/YYYY")###)

And if you get daring, you can try this:

INSERT INTO Ads(adIssue)
VALUES(###CreateODBCDate(myadissue)###)

 

by: istomtomPosted on 2003-04-09 at 10:29:07ID: 8301295

Anand, I am not using single quotes.. the outer quotes are put there by CF when it outputs the error, the inner quotes are put there by CreateODBCDate. I tried the suggestions you made in various formats CreateODBCDate(FORM.adissue), CreateODBCDateTime(FORM.adissue) and they all cause the malformed guid error.

I tried dash420's suggestion #DateFormat(FORM.adissue,"mm/dd/yyyy")# and this caused the date to be inserted into the database, BUT, it inserted it as a time actually and gave me some date in the year 1899.

TallerMike, I know for a fact that CreateODBCDate can be used with SQL as my CF4 book tells me it's meant specifically to create a date object compatible with SQL, as is CreateODBCDateTime as well. Your suggestion of ###CreateODBCDate(myadissue)### causes CF to return a syntax error. Syntax error in date in query expression '#{d '2003-04-12'}#'. Again, as I stated above, the outer single quotes are put there when CF outputs the error, they're not in my SQL code.

On an interesting note, I recalled from scripts written long ago that I've had date/time issues using OLEDB connections before. So I switched my db connection to ODBC and my original code worked flawlessly. This still doesn't satisfy my frustration as to how to insert a date and/or time into an access db connected via OLEDB. I've increased the points to 150 if anyone wants to take a crack at figuring this out for sure as I seem to recall there are several reasons to use OLEDB instead of ODBC.

 

by: shooksmPosted on 2003-04-09 at 10:50:50ID: 8301451

Try this:

INSERT INTO Ads(adIssue)
VALUES(<cfqueryparam cfsqltype="cf_sql_date" value="#FORM.adIssue#">)

 

by: TallerMikePosted on 2003-04-09 at 11:11:47ID: 8301572

I'm not denying that CreateODBCDate will work with SQL, but Access is a different breed of SQL. At one point in time, Access liked to have dates surrounded by pound signs. Do a search on the web for your problem through Yahoo and you will see that using pound signs to resovle similar problems is not so unusual. Some examples:

http://p2p.wrox.com/archive/pro_vb/2001-05/114.asp
http://www.experts-exchange.com/Web/WebDevSoftware/ColdFusion/Q_20155678.html


Please also note this post from the following link:
http://cfmxplus.blogspot.com/2002_11_10_cfmxplus_archive.html

Date processing with Access in CF
Some folks have had problems doing date processing within SQL against an Access database. (Let's not get into whether anyone should be choosing Access as a DB. For some low volume sites, it works adequately.)

Part of the date handling problem stems from the fact that Access may need help determining that what you're passing it is a date (versus a number). There are two ways to do this. You could use the CreateODBCDate() function to convert a date to a format that will be passed from CF to SQL as an ODBC Formatted date.

Another is to take advantage of the fact that Access can use pound signs around a date to indicate that the value is a date. Of course, those are the same pound signs that CF uses for variables, which can complicate things.

First, just know that one way to format a SQL statement WITHIN Access to process, for instance, records between two dates (leave CF out of the picture for a moment) would be to render it as:

SELECT StartDate FROM Employee WHERE StartDate between #01/01/97# and #01/01/98#

If you wanted to do that within a CFQUERY statement, then you'd need to escape those pound signs (double them) so that CF didn't think you were trying to refer to variables, as in:

<CFQUERY NAME="test" DATASOURCE="CompanyInfo">
SELECT StartDate FROM Employee WHERE StartDate between ##01/01/97## and ##01/01/98##
</CFQUERY>

Of course, you could also convert this to use the ODBCDateFormat function, as in:

<CFQUERY NAME="test" DATASOURCE="CompanyInfo">
SELECT StartDate FROM Employee WHERE StartDate between #ODBCDateFormat("01/01/97")# and #ODBCDateFormat("01/01/98")#
</CFQUERY>

Notice again that the use of this function doesn't require the use of escaped pound signs because the function creates the date in a format Access understands. But you'll usually have the date coming in as a variable. You could then easily change the ODBCDateFormat as in:

<cfset date="01/01/98">
<CFQUERY NAME="test" DATASOURCE="CompanyInfo">
SELECT StartDate FROM Employee WHERE StartDate between #ODBCDateFormat("01/01/97")# and #ODBCDateFormat(date)#
</CFQUERY>

But if you tried to use the Access form of passing pound-delimited dates, such as in the first two examples above, and you wanted to use a variable for one of them, you'd then need 3 pound signs around that (two for the escaped pound for Access and one for the pound needed to refer to the variable/function), as in:

<cfset date="01/01/98">
<CFQUERY NAME="test" DATASOURCE="CompanyInfo">
SELECT StartDate FROM Employee WHERE StartDate between ##01/01/97## and ###date###
</CFQUERY>

Finally, note that if you wanted to use the now() function in that last example for the date (which returns the current date AND time), or if your incoming "date" variable had minutes and seconds in it, you'd need to wrap it in a dateformat function before using the "pound sign" approach to date formatting in Access because that doesn't like anything but a date to be passed in, as in:.

<CFQUERY NAME="test" DATASOURCE="CompanyInfo">
SELECT StartDate FROM Employee WHERE StartDate between ##01/01/97## and ###dateformat(now())###
</CFQUERY>

Note, too, that I've not bothered with any date formatting "mask". In my testing, Access is happy with the default dateformat form of date layout.

So when should you use the pound sign approach? Well, really, it's more something that's needed within Access itself to be able to detect that a string of numbers (and dashes or slashes) are in fact representing a date. The thing is, with the ODBCDateFormat function (and CF's Now() returning a date in ODBCDateTime Format), it's perhaps not as important to use the pound-surrounded approach to dates in Access.

posted by Charli

 

by: TallerMikePosted on 2003-04-09 at 11:16:15ID: 8301601

More from the following link:

http://www.maxfusion.co.uk/faq/viewfaq.cfm?QID=168

Q. How do I insert a date into my Access database?

The Problem: You want to insert a date into a date/time
field in your Access database. The Solution: You can
approach this either by inserting a properly formatted
string which Access will then convert into a date/time
object, or by creating one yourself. Either way will work.

<cfset myDate = "DateFormat(now(),"m/d/yy")>
<cfset myDate2 = CreateODBCDate(now())>

<cfquery...>
 INSERT INTO myTable(date1, date2)
 VALUES('#myDate#',#myDate2#)
</cfquery>

 

by: substandPosted on 2003-04-09 at 16:10:20ID: 8303508

i always put single quotes around mine, and it worked.

 

by: TallerMikePosted on 2003-04-09 at 16:18:00ID: 8303541

Around your CreateODBCDate functions? Weird... I know in Oracle at least, if you put single quotes around fields that don't require them, that it slows down the server because it trys to convert the value from a string to whatever it needs. This is the case for numeric fields, not sure if it applies to date fields though?

 

by: substandPosted on 2003-04-09 at 16:41:31ID: 8303649

no, sorry, see another post of mine =) i mean around dateFormat...

i don't know that i've ever tried it with createODBCdatetime.. although i have found alot of differences between acceptable and required syntax depending on if you are using oracle, ms sql server, or access.

those are the only ones i've used, but any time i convert and app from one to the other, it's almost assured that i have to change some sort of syntax in some way or another.

Just a fun story about the differences: Before I knew anything about oracle, i knew alot about ms sql server, and I took a DB class in college that was based on sql server. So i figured I didn't need to study or go to class, and answered questions as I would have in ms sql server.  well, when the course was over, I had a C-.  I thought I had an A since I work on this stuff every day.

 

by: anandkpPosted on 2003-04-09 at 22:10:29ID: 8304830

I never used single quotes for oracle & sql ! & in both ive used CreateODBCDateTime() to insert datetime into the DB [if time is not required - just use CreateODBCDate()]

its really weird y ur query wont work !

make sure - ur checking the right cfm page, in the respective application & connecting to the respective DB

if everything is set up well - the query suggested shld definately work !

K'Rgds
Anand

 

by: dash420Posted on 2003-04-10 at 02:11:13ID: 8305695

Anand,
single quotes is not required if it is date data type. as
CreateODBCDate() is a date type. so single quotes is not required. if it is a string datatype then single quote is must. I always used single quotes as never like CreateODBCDate(). That is personal choice.

 

by: istomtomPosted on 2003-04-23 at 16:12:46ID: 8384223

Well, nothing I've tried has worked with Access when connecting via an OLEDB DSN connection. So, I've given up trying to use OLEDB and have changed the DSN to ODBC and my original code works fine.

Thanks guys. I don't really know who to award the points to so I'm going to close my eyes, scroll the page up & down, and point at one at random.

 

by: substandPosted on 2003-04-23 at 16:19:19ID: 8384246

thats funny.  i never even noticed that this was regarding oledb and not odbc until you just posted that.

thats probably why nothing we said worked, since most of it revolved around "createODBCdatetime"

haha

 

by: TallerMikePosted on 2003-04-23 at 16:26:39ID: 8384282

WooHoo! I won!

 

by: anandkpPosted on 2003-04-23 at 21:30:21ID: 8385933

:) heh :)

 

by: anandkpPosted on 2003-04-23 at 21:45:02ID: 8386019

:) heh :)

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...