troubles with performing a dsn-less conection Insert into a SQL server

matthersw used Ask the Experts™
I am having troubles with performing a dsn-less conection Insert into a SQL server. Below is my code:
<!---Include the ADO Defines file--->
<cfinclude template="includes/adocfscript.cfm">

<!---Create variables from form data--->
<CFSET varFName="#Form.FName#">
<CFSET varLName="#Form.LName#">

<!---insert variables into William_Demo table--->
CONNECTSTRING="Driver={SQL Server};Server=servername;Database=databasename;Uid=userid;Pwd=password;">
Insert into William_Demo (FName, LName) Values("#varFName#","#varLName#")

<body bgcolor="#FFFFFF">
<!---write variables--->
Data to be entered into the db table:

First Name: #varFName#

Last Name: #varLName#

<!--query William_Demo table for all data--->
<CFQUERY NAME="Names_Query"
CONNECTSTRING="Driver={SQL Server};Server=servername;Database=databasename;Uid=userid;Pwd=password;"
SELECT FName, LName from William_Demo
All data from the Names Table

<table width="300" border="1">
<th width="150">First Name</th>
<th width="150">Last Name</th>
<!---write all data--->
<cfoutput query="Names_Query">
<td width="150">#Names_Query.FName#</td>
<td width="150">#Names_Query.LName#</td>
My error is:
Error Diagnostic Information
ODBC Error Code = 37000 (Syntax error or access violation)
[Microsoft][ODBC SQL Server Driver][SQL Server]The name 'Tom' is not permitted in this context. Only constants, expressions, or variables allowed here. Column names are not permitted.

SQL = "Insert into William_Demo (FName, LName) Values("Tom","Jones")"

Data Source = ""

The error occurred while processing an element with a general identifier of (CFQUERY), occupying document position (9:1) to (11:97) in the template file D:\William_Demo\INSERT1.CFM.
Any ideas why this will not work?


Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
use single quotes

Insert into William_Demo (FName, LName) Values('#varFName#','#varLName#')


Thanks; worked like a charm.


Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial