anup001
asked on
Sql coldfusion error ( field not getting updated)
Hi,
I am trying to insert some numeric data from a few form fields into the database table(MS SQL 2000). Now if one of those fields in blank it should not matter to me however it is trhowing me an error in such a case if a field or two is blank. I do not get such an error with the fields that are inserted into the varchar type in database.
Here is the error:
Error Executing Database Query.
[Macromedia][SQLServer JDBC Driver][SQLServer]Error converting data type varchar to numeric.
The error occurred in E:\docs_secure\icepe\act_u pdate.cfm: line 133
Called from E:\docs_secure\icepe\act_u pdate.cfm: line 1
Called from E:\docs_secure\icepe\act_u pdate.cfm: line 133
Called from E:\docs_secure\icepe\act_u pdate.cfm: line 1
131 : voltage='#Form.voltage#',
132 : calc_gpr_peak_asym='#Form. gprpeaka#'
133 : WHERE site_id='#Form.sid#'
134 : </CFQUERY>
135 : <cfelse>
Initially i did as follows which was not working
<cflock name="insertrecord_gpr" timeout="10">
<cfquery datasource="sqldatas" username="****" password="***">
insert into gpr_info (grid_area, grid_resistance, gro_fau_duty, site_id, xr_ratio, voltage, calc_gpr_peak_asym)
values('#EVALUATE('form.gr idarea')#' ,'#EVALUAT E('form.gr id_resista nce')#','# EVALUATE(' form.gro_f au_duty')# ','#EVALUA TE('form.s id')#','#E VALUATE('f orm.xrrati o')#'
,'#EVALUATE('form.voltage' )#','#EVAL UATE('form .gpr_asym' )#')
</cfquery>
</cflock>
Then after some guidance from EE i did the folllowing but insert worked and update did not
This is what i did
Follwing update query did not work as it is not replacing(updating) the value with a blank or null when the user leves the value as blank in the submitting form field.
<CFQUERY datasource="sqldatas" name="updategpr" username="**** password="***">
UPDATE gpr_info
SET grid_area=<cfqueryparam value="#FORM.gridarea#" null="#iif( len( form.gridarea ), dE( "no" ), dE("yes" ) )#">,
grid_resistance=<cfquerypa ram value="#FORM.gridresist#" null="#iif( len( form.gridresist ), dE( "no" ), dE("yes" ) )#">,
gro_fau_duty=<cfqueryparam value="#FORM.groduty#" null="#iif( len( form.groduty ), dE( "no" ), dE("yes" ) )#">,
xr_ratio=<cfqueryparam value="#FORM.xrratio#" null="#iif( len( form.xrratio ), dE( "no" ), dE("yes" ) )#">,
voltage=<cfqueryparam value="#FORM.voltage#" null="#iif( len( form.voltage ), dE( "no" ), dE("yes" ) )#">,
calc_gpr_peak_asym=<cfquer yparam value="#FORM.gprpeaka#" null="#iif( len( form.gprpeaka ), dE( "no" ), dE("yes" ) )#">
WHERE site_id='#Form.sid#'
</CFQUERY>
However it works for insert as it enters blank or null in the database if i enter blank field in the submitting form
<cfquery datasource="sqldatas" username="****" password="****">
insert into gpr_info (grid_area, grid_resistance, gro_fau_duty, site_id, xr_ratio, voltage, calc_gpr_peak_asym)
values(<cfqueryparam value="#FORM.gridarea#" null="#iif( len( form.gridarea ), dE( "no" ), dE("yes" ) )#">,<cfqueryparam value="#FORM.gridresist#" null="#iif( len( form.gridresist ), dE( "no" ), dE("yes" ) )#">,<cfqueryparam value="#FORM.groduty#" null="#iif( len( form.groduty ), dE( "no" ), dE("yes" ) )#">,'#EVALUATE('form.sid' )#',<cfque ryparam value="#FORM.xrratio#" null="#iif( len( form.xrratio ), dE( "no" ), dE("yes" ) )#">
,<cfqueryparam value="#FORM.voltage#" null="#iif( len( form.voltage ), dE( "no" ), dE("yes" ) )#">,<cfqueryparam value="#FORM.gprpeaka#" null="#iif( len( form.gprpeaka ), dE( "no" ), dE("yes" ) )#">)
</cfquery>
Thanks
Anup
I am trying to insert some numeric data from a few form fields into the database table(MS SQL 2000). Now if one of those fields in blank it should not matter to me however it is trhowing me an error in such a case if a field or two is blank. I do not get such an error with the fields that are inserted into the varchar type in database.
Here is the error:
Error Executing Database Query.
[Macromedia][SQLServer JDBC Driver][SQLServer]Error converting data type varchar to numeric.
The error occurred in E:\docs_secure\icepe\act_u
Called from E:\docs_secure\icepe\act_u
Called from E:\docs_secure\icepe\act_u
Called from E:\docs_secure\icepe\act_u
131 : voltage='#Form.voltage#',
132 : calc_gpr_peak_asym='#Form.
133 : WHERE site_id='#Form.sid#'
134 : </CFQUERY>
135 : <cfelse>
Initially i did as follows which was not working
<cflock name="insertrecord_gpr" timeout="10">
<cfquery datasource="sqldatas" username="****" password="***">
insert into gpr_info (grid_area, grid_resistance, gro_fau_duty, site_id, xr_ratio, voltage, calc_gpr_peak_asym)
values('#EVALUATE('form.gr
,'#EVALUATE('form.voltage'
</cfquery>
</cflock>
Then after some guidance from EE i did the folllowing but insert worked and update did not
This is what i did
Follwing update query did not work as it is not replacing(updating) the value with a blank or null when the user leves the value as blank in the submitting form field.
<CFQUERY datasource="sqldatas" name="updategpr" username="**** password="***">
UPDATE gpr_info
SET grid_area=<cfqueryparam value="#FORM.gridarea#" null="#iif( len( form.gridarea ), dE( "no" ), dE("yes" ) )#">,
grid_resistance=<cfquerypa
gro_fau_duty=<cfqueryparam
xr_ratio=<cfqueryparam value="#FORM.xrratio#" null="#iif( len( form.xrratio ), dE( "no" ), dE("yes" ) )#">,
voltage=<cfqueryparam value="#FORM.voltage#" null="#iif( len( form.voltage ), dE( "no" ), dE("yes" ) )#">,
calc_gpr_peak_asym=<cfquer
WHERE site_id='#Form.sid#'
</CFQUERY>
However it works for insert as it enters blank or null in the database if i enter blank field in the submitting form
<cfquery datasource="sqldatas" username="****" password="****">
insert into gpr_info (grid_area, grid_resistance, gro_fau_duty, site_id, xr_ratio, voltage, calc_gpr_peak_asym)
values(<cfqueryparam value="#FORM.gridarea#" null="#iif( len( form.gridarea ), dE( "no" ), dE("yes" ) )#">,<cfqueryparam value="#FORM.gridresist#" null="#iif( len( form.gridresist ), dE( "no" ), dE("yes" ) )#">,<cfqueryparam value="#FORM.groduty#" null="#iif( len( form.groduty ), dE( "no" ), dE("yes" ) )#">,'#EVALUATE('form.sid'
,<cfqueryparam value="#FORM.voltage#" null="#iif( len( form.voltage ), dE( "no" ), dE("yes" ) )#">,<cfqueryparam value="#FORM.gprpeaka#" null="#iif( len( form.gprpeaka ), dE( "no" ), dE("yes" ) )#">)
</cfquery>
Thanks
Anup
i mean
where site_id = #form.sid#
where site_id = #form.sid#
ASKER
This is question is already solved in some other question. Please do not answer for this anymore. I am requesting to delete it.
Thanks for your help though.And adonis1976 what u told did not work. It is not that simple . Thanks for your help though. Much appreciated.
Anup
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
where site_id = '#form.site_id#'
try this
where site_id = #form.site_id#