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

matthersw
matthersw used Ask the Experts™
on
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--->
<CFQUERY NAME="Insert"
DBTYPE="dynamic"
CONNECTSTRING="Driver={SQL Server};Server=servername;Database=databasename;Uid=userid;Pwd=password;">
Insert into William_Demo (FName, LName) Values("#varFName#","#varLName#")
</CFQUERY>


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

First Name: #varFName#

Last Name: #varLName#
</CFOUTPUT>

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

<table width="300" border="1">
<tr>
<th width="150">First Name</th>
<th width="150">Last Name</th>
</tr>
<!---write all data--->
<cfoutput query="Names_Query">
<tr>
<td width="150">#Names_Query.FName#</td>
<td width="150">#Names_Query.LName#</td>
</tr>
</cfoutput>
</table>
</html>
----------------------------------------------------------------------------
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?

Thanks,

Wills
Comment
Watch Question

Do more with

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

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

Author

Commented:
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