我到处都看了,我找不到答案。
以下是我使用ColdFusion和MsSQL
时遇到的错误Error Executing Database Query.
[Macromedia][SQLServer JDBC Driver][SQLServer]Conversion failed when converting date and/or time from character string.
The error occurred in SQL
INSERT INTO Requests (
RequestName,
RequestEmail,
RequestPhone,
RequestType,
RequestSiteSection,
RequestDue,
RequestUrgent,
RequestTitle,
RequestURL,
RequestMessage,
Attachment1,
Attachment2,
Attachment3,
Attachment4,
Attachment5,
RequestCreated,
RequestModified,
RequestPriority,
RequestAssignedTo,
RequestStatus
)
VALUES (
'',
'Joshua >Davis',
'onebigcelt@gmail.com',
'8046789',
'Correction',
'Natural Heritage',
'09/11/2013',
'This is the Title of the REQUEST!',
'http://www.dcr.virginia.com',
'rewas',
'/opt/coldfusion8/runtime/servers/coldfusion/SERVER-INF/temp/wwwroot-tmp/neotmp47128.tmp',
'',
'',
'',
'',
(param 1),
(param 2),
'0',
'Webmaster',
'Pending'
)
每个参数都是cfqueryparam cfsqltype='CF_SQL_timestamp' value='#CreateODBCDateTime(now())#'
当我尝试使用以下任何一种
进行插入时,会出现此错误我尝试将时间和日期连接在一起,投射并转换为日期时间,形成日期和时间,但没有运气我被卡住了。
感谢您的帮助。
这是查询
INSERT INTO Requests (
RequestName,
RequestEmail,
RequestPhone,
RequestType,
RequestSiteSection,
RequestDue,
RequestUrgent,
RequestTitle,
RequestURL,
RequestMessage,
Attachment1,
Attachment2,
Attachment3,
Attachment4,
Attachment5,
RequestCreated,
RequestModified,
RequestPriority,
RequestAssignedTo,
RequestStatus
)
VALUES(
'<cfif IsDefined('form.requestUrgent')>#form.requestUrgent#</cfif>',
'#form.requestName#',
'#form.requestEmail#',
'#form.requestPhone#',
'#form.requestType#',
'#form.requestSection#',
'#form.requestDueDate#',
'#form.requestTitle#',
'#form.requestURL#',
'#form.requestMessage#',
'#form.attachment1#',
'#form.attachment2#',
'#form.attachment3#',
'#form.attachment4#',
'#form.attachment5#',
getdate(),
getdate(),
'0',
'Webmaster',
'Pending'
)
您可以使用以上任何选项getDate()
转换为演员,参数等来#var#
答案 0 :(得分:5)
来自评论
插入查询中的列和值似乎在示例代码中处于关闭状态。您的插入以列RequestName
开头,但VALUES子句中的第一个变量是form.requestUrgent
,然后是form.requestName
等。因此,您的查询尝试插入form.requestSection
('将自然遗产(在您的示例中)放入日期栏RequestDue
。
摘自你的例子:
INSERT INTO Requests (
RequestName, /* column 1 */
RequestEmail, /* column 2 */
RequestPhone, /* column 3 */
RequestType, /* column 4 */
RequestSiteSection, /* column 5 */
RequestDue, /* column 6 */
RequestUrgent, /* column 7 */
RequestTitle, /* column 8 */
....
VALUES (
'<cfif IsDefined('form.requestUrgent')>#form.requestUrgent#</cfif>', /* value 1 */
'#form.requestName#', /* value 2 */
'#form.requestEmail#', /* value 3 */
'#form.requestPhone#', /* value 4 */
'#form.requestType#', /* value 5 */
'#form.requestSection#', /* value 6 */
'#form.requestDueDate#', /* value 7 */
'#form.requestTitle#', /* value 8 */
....
我无法强调您应该为所有变量值使用<cfqueryparam>
标记。它有助于protect against SQL injection以及improves query performance。