INSERT查询错误:不允许从数据类型varchar到varbinary的隐式转换。使用CONVERT函数运行此查询。

时间:2012-06-28 13:43:16

标签: sql sql-server coldfusion

我正在尝试运行插入查询,但我收到以下错误。如何将值传递给insert语句?该值来自数组,[cNotes]列类型为varchar NULL

提前致谢。

错误:

        Error Executing Database Query.  
        [Macromedia][SQLServer JDBC Driver][SQLServer]Implicit conversion from data type varchar    to varbinary is not allowed. Use the CONVERT function to run this query.  

         The error occurred in C:\Inetpub\wwwroot\Components\Assessment.cfc: line 510
       Called from C:\Inetpub\wwwroot\Components\Assessment.cfc: line 440

          508 :                      ,NULL
          509 :                  </cfif>
          510 :                   ,'#arguments.notes#') 
           511 :        </cfquery>
          512 :     </cffunction> 



           --------------------------------------------------------------------------------

            SQL    INSERT INTO AssessmentToolDetail(iAssessmentToolMaster_ID ,iServiceList_ID   ,cRowStartUser_ID ,Service_text ,cNotes) Values(251069 ,3592 ,NULL ,'y ' ,'')   
           DATASOURCE   TIPS4 
             VENDORERRORCODE   257 
            SQLSTATE   HY000 '

CFC功能:

<cffunction name="AddService" access="public" returntype="void" output="false">
    <cfargument name="ServiceList" type="Components.ServiceList"  required="true">
    <cfargument name="notes" type="string" required="false" default="">
    <cfargument name="serviceText" type="string" required="false" default="">       

    <cfquery name="AddServiceListQuery" datasource="#variables.dsn#">
        INSERT INTO AssessmentToolDetail (
                iAssessmentToolMaster_ID
                , iServiceList_ID
                , cRowStartUser_ID
                , Service_text
                , cNotes )
        VALUES (
               #variables.id#
                ,#ServiceList.GetId()#              
                <cfif variables.rowStartUserId neq "">
                    , '#variables.rowStartUserId#'
                <cfelse>
                    , NULL
                </cfif>
                <cfif ListFirst( Arguments.serviceText,'_' ) EQ ServiceList.GetId() >
                    , '#Left(ListLast( Arguments.serviceText,'_'),1)# '
                <cfelse>
                    , NULL
                </cfif>
                ,  '#arguments.notes#'
              ) 
    </cfquery>
</cffunction>

1 个答案:

答案 0 :(得分:4)

错误是说您正在尝试将字符串插入具有二进制存储格式的列中,并且它无法隐式进行转换。

检查cNotes表中的AssessmentToolDetail列的数据类型是varchar(n)还是nvarchar(n)而不是varbinary(n)