Querying SQL server 2000 from within coldfusion
-
28-09-2019 - |
문제
I'm trying to execute the following CFML:
<cfquery name="koppelData" datasource="#request.DataSource#">
INSERT INTO t_user_profile
(Username, ProfileID, AanvraagID)
VALUES
(<cfqueryparam cfsqltype="cf_sql_varchar" value="#FORM.username#">,
<cfqueryparam cfsqltype="cf_sql_integer" value="#laatste#">),
<cfqueryparam value="#FORM.vragenlijst#" cfsqltype="cf_sql_integer" >)
</cfquery>
This throws the following error (my version of SQL server is dutch):
[Macromedia][SQLServer JDBC Driver][SQLServer]De INSERT-instructie bevat meer kolommen dan er waarden zijn opgegeven in de VALUES-component. Het aantal waarden in de VALUES-component moet overeenkomen met het aantal kolommen in de INSERT-instructie.
This is basically translated as follows: The INSERT instruction contains more columns as there are values specified in the VALUES statement. The number of fields in the VALUES statement must be equal to the number of fields in the INSERT statement.
What did I do wrong?
Edit:
Single quotes don't help, as in:
Error Executing Database Query.
[Macromedia][SQLServer JDBC Driver]Invalid parameter binding(s).
The error occurred in C:\Users\Adm1n\Adobe ColdFusion Builder workspace\PASS\jsexec\maak_lid.cfm: line 52
50 : '<cfqueryparam cfsqltype="cf_sql_varchar" value="#FORM.username#">',
51 : <cfqueryparam cfsqltype="cf_sql_integer" value="#laatste#">),
52 : <cfqueryparam value="#FORM.vragenlijst#" cfsqltype="cf_sql_integer" >
53 : )
54 : </cfquery>
Found it: take a look at the second parameter, last character:
<cfqueryparam cfsqltype="cf_sql_integer" value="#laatste#">),
It was a typ0 :-S
해결책
You have an extra parenthessis at the end of the second parameter. All in all:
<cfquery name="koppelData" datasource="#request.DataSource#">
INSERT INTO
t_user_profile
(Username, ProfileID, AanvraagID)
VALUES
(
<cfqueryparam cfsqltype="cf_sql_varchar" value="#FORM.username#">,
<cfqueryparam cfsqltype="cf_sql_integer" value="#laatste#">,
<cfqueryparam value="#FORM.vragenlijst#" cfsqltype="cf_sql_integer" >
)