1

我找遍了整个地方,我找不到答案。

这是我在使用 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())#'

当我尝试使用以下任何一种插入时出现此错误

  • cfqueryparam cfsqltype='CF_SQL_timestamp' value='#CreateODBCDateTime(now())#'
  • 现在()
  • CreateODBCDateTime(now())
  • SQL 获取日期()
  • 其他变体

我尝试将时间和日期连接在一起,转换并转换为 datetime ,格式化日期和时间,但没有运气我被卡住了。

我感谢您的帮助。

这是查询

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#转换强制转换、参数等

4

1 回答 1

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>为所有变量值使用标签。它有助于防止 SQL 注入提高查询性能

于 2013-09-25T18:06:24.867 回答