Coldfusion:处理日期字段中的Null值 [英] Coldfusion: Dealing with Null values in Date Field

查看:258
本文介绍了Coldfusion:处理日期字段中的Null值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这种表格,提供各种员工认证,我需要输入日期。有时这个日期将是未来几个月的其他时间,日期将被定义为null。

I've got this form with all kinds of employee certifications, I need to input a date. Sometimes this date will be months in the future other times the date will be undefined, null.

每当我尝试向我的CFC传递一个空值时,我总是得到一个如下的错误:

Whenever I try to pass a null value to my CFC, I always get an error that looks like:


传递给addEmployee函数的CPRADULTEXP参数不是类型日期。

The CPRADULTEXP argument passed to the addEmployee function is not of type date.

我的表单代码: / p>

My Form code:

<!--- If null, set a default if not, set the default to database default --->
<cfif not isDefined("certificationsList.cprAdultExp")>
<cfinput type="datefield" required="no" name="cprAdultExp" value="" >
<cfelse>
<cfinput type="datefield" required="no" name="cprAdultExp" value="#dateformat(certificationsList.cprAdultExp, "mm/dd/yyyy")#" >
</cfif>

表单处理程序:

<!--- Is the date defined? --->
<cfif len(Trim("form.cprAdultExp"))  EQ 0>
<cfinvokeargument name="cprAdultExp" value="#CreateODBCDate(Form.cprAdultExp)#">
<cfelse>
<cfinvokeargument name="cprAdultExp" value="">
</cfif>    

现在它传递的是null值,数据库设置为handle / accept nulls。

Right now it's passing that null value, the database is set to handle/accept nulls.

如何解决?

推荐答案

您将省略最重要的部分 - 实际的CFC和执行插入的查询。发生了什么是你的< cfargument> 标签被键入为'date',所以当你传递一个空字符串验证失败。 (这是我不输入参数的原因之一)。

You're leaving out the most important part - the actual CFC and the query that does the insert. What's happening is your <cfargument> tag is typed as 'date' so when you pass an empty string the validation fails. (This is one of the reasons I don't type my arguments).

您需要关闭类型检查或将参数类型更改为string或any。现在,当您这样做时,您还需要更改< cfqueryparam> 标签(您 使用 ; cfqueryparam> ,不是吗?!)到这样的东西:

You'll need to either turn off type checking or change the argument type to 'string' or 'any'. Now, when you do that you'll also need to change your <cfqueryparam> tag (you are using <cfqueryparam>, aren't you?!) to something like this:

<cfqueryparam .... null="#not len(trim(arguments.thedate))#" />

这将修复ya ...

That'll fix ya...

这篇关于Coldfusion:处理日期字段中的Null值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆