CFC & Null Date & Access

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default 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

  2. Similar Questions and Discussions

    1. 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...
    2. 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...
    3. 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...
    4. 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; ?>...
    5. 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
  3. #2

    Default 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

  4. #3

    Default 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

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139