Ask a Question related to Coldfusion Database Access, Design and Development.
-
neilsytner #1
CFC & Null Date & Access
hi all,
i'm stumped on the following problem, and below is some simple example code of
the problem.
i would like to know how to UPDATE the 'yourDOB' field with a NULL value is no
date is entered.
how would i go about this?
thankyou in advance for any responses!
form.cfm and dateTest.cfc
<cfif IsDefined("form.dateTestSubmit")>
<cfinvoke component="components.dateTest" method="updateDetails">
<cfinvokeargument name="yourID" value="#form.yourID#" />
<cfinvokeargument name="yourName" value="#form.yourName#" />
<cfinvokeargument name="yourDOB" value="#form.yourDOB#" />
</cfinvoke>
<cfelse>
<html>
<head>
<title>Test</title>
</head>
<body>
<form action="#cgi.script_name#" method="post" name="dateTest" id="dateTest">
<label for="yourName">Full name:</label>
<input type="text" name="yourName" id="yourName" value="" />
<br />
<label for="yourDOB">Date of birth:</label>
<input type="text" name="yourDOB" id="yourDOB" value="" />
<br />
<input type="hidden" name="yourID" id="yourID" value="#someQuery.yourID#" />
<input type="submit" name="dateTestSubmit" id="dateTestSubmit" value="Test" />
</form>
</body>
</html>
</cfif>
------------
<cfcomponent output="no">
<cfsilent>
<cfset variables.dsn = "yourDSN" />
<cffunction name="updateDetails" access="public" output="false"
hint="Updates the user name and date of birth.">
<cfargument name="yourID" type="numeric" required="yes" />
<cfargument name="yourName" type="string" required="no" default="string" />
<cfargument name="yourDOB" type="date" required="no" default="date" />
<cfquery datasource="#variables.dsn#">
UPDATE tblDetails
SET yourName = <cfqueryparam cfsqltype="cf_sql_char"
value="#arguments.yourName#" />,
yourDOB = <cfqueryparam cfsqltype="cf_sql_timestamp"
value="#arguments.yourDOB#" />
WHERE yourID = <cfqueryparam cfsqltype="cf_sql_integer"
value="#arguments.yourID#" />
</cfquery>
<cfreturn />
</cffunction>
</cfsilent>
</cfcomponent>
neilsytner Guest
-
null date error problem
Hi all I have a strange problem with using web services. I have a web services that sends more than one variable as a result. if one of those... -
Simple Dumb Question - Null for Date/Time Field
using cf mx ms sql 2000. i have an update form that contains a field for date a procedure was signed. the problem is if the procedure was not... -
ASP SQL Insert NULL Date Value
Hello, I've been pulling my hair out trying to figure this out. Thank you in advance for taking the time to look at this. I'm trying to... -
html display for date with null value
I have some date fields which in some records will have NULL value. I am trying to show nothing in the HTML display. IF <? $date3=$myrow; ?>... -
testing for a null Date in the Filter property of a RecordSet object?
Hello, I am new to using the filter property. When I try publishDate = '' I get a type mismatch error. Any ideas? Thanks Rich -
neilsytner #2
Re: CFC & Null Date & Access
OK - the following seems to work, but i would really appreciate anyone's
thoughts on whether this is the correct way of doing it or not.
<cfif form.yourDOB NEQ ""><cfinvokeargument name="yourDOB"
value="#CreateODBCDateTime(form.yourDOB)#" /><cfelse><cfinvokeargument
name="yourDOB" value="" /></cfif>
------------------
<cfargument name="yourDOB" type="string" required="no" default="" />
------------------
yourDOB = <cfqueryparam cfsqltype="cf_sql_timestamp"
null="#YesNoFormat(Compare(Trim(arguments.yourDOB) ,"") EQ 0)#"
value="#arguments.yourDOB#" />,
neilsytner Guest
-
Dan Bracuk #3
Re: CFC & Null Date & Access
The correct way is "whatever works". My recommendation is to do write code
that creates as string variable as per the following logic.
If your form field is empty, set your date field variable to "null"
If form field has data, check to see if it is represents a date. If not, do
what you think is appropriate for your application. If so, use dateformat and
maybe timeformat to set your date field variable to either
"{d 'yyyy-mm-dd'}"
or
"{ts 'yyyy-mm-dd hh:mm:ss'}"
Use your date variable, with the Preservesinglequotes function in your query.
Dan Bracuk Guest



Reply With Quote

