Print Page | Close Window

insert into table

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=4008
Printed Date: 30 March 2026 at 3:26am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: insert into table
Posted By: beginner
Subject: insert into table
Date Posted: 02 July 2003 at 11:02am

Hi,

i'm trying to insert some records into the table and i keep getting errors. the error that i get is:

Error Type:
Microsoft OLE DB Provider for SQL Server (0x80040E14)
Line 1: Incorrect syntax near '27'.
/agencyForm.asp, line 20

 

Here is the code that i can't quiet get to work:

<%
sub WriteRecord
'Creating the database connection
 Dim Cn, strSQL, commandObject
    Set Cn = Server.CreateObject("ADODB.Connection")
    Cn.Open Application("Connection3_ConnectionString")
   
    Set commandObject= Server.CreateObject("ADODB.Command")
    Set commandObject.ActiveConnection = Cn
   
    strSQL = "INSERT INTO application"
    strSQL = strSQL + " VALUES("
    strSQL = strSQL + "'" +"'"&Request.Form("ApplName")&"'"+ "'"
    strSQL = strSQL + "'" + "'"&Session("Username")&"'" + "'"
    strSQL = strSQL + ")"
   
   
    commandObject.CommandText = strSQL
    commandObject.Execute
end sub

if Request.Form.Count => 0 then
 Call WriteRecord
end if
%>

Can somebody maybe send me an exmple of an insert statement that they used and that works.

Thanks

 





Replies:
Posted By: ljamal
Date Posted: 02 July 2003 at 11:21am
You need to add a commas between the values insert. The syntax is

insert into table [(field1,field2,field3,etc)] values (value1,value2,value3)

Defining the fields is not required but is good practice, just in case the database table changes later. The values need to be surrounded by a single quote (') if non-numeric.

-------------
L. Jamal Walton

http://www.ljamal.com/" rel="nofollow - L. Jamal Inc : Web/ Print Design and ASP Programming


Posted By: beginner
Date Posted: 02 July 2003 at 11:45am

I have changed it to this now but it still doesn't work.

 

<%
sub WriteRecord
'Creating the database connection
  Dim Cn, strSQL, commandObject
    Set Cn = Server.CreateObject("ADODB.Connection")
    Cn.Open Application("Connection3_ConnectionString")
   
    Set commandObject= Server.CreateObject("ADODB.Command")
    Set commandObject.ActiveConnection = Cn
   
    strSQL = "INSERT INTO application"
    strSQL = strSQL & " VALUES('Request.Form("ApplName"), '"&Session("Username")&"'')" 
       
    commandObject.CommandText = strSQL
    commandObject.Execute
end sub

if Request.Form.Count => 0 then
 Call WriteRecord
end if
%>

This is the error i get:

  • Error Type:
    Microsoft VBScript compilation (0x800A0401)
    Expected end of statement
    /agencyForm.asp, line 13, column 42


  • Posted By: ljamal
    Date Posted: 02 July 2003 at 12:23pm
    This line :
        strSQL = strSQL & " VALUES('Request.Form("ApplName"), '"&Session("Username")&"'')"

    should be:

        strSQL = strSQL & " VALUES('"&Request.Form("ApplName")&"', '"&Session("Username")&"')"

    -------------
    L. Jamal Walton

    http://www.ljamal.com/" rel="nofollow - L. Jamal Inc : Web/ Print Design and ASP Programming


    Posted By: beginner
    Date Posted: 02 July 2003 at 12:45pm
    Now i'm not getting any errors but it's not inserting anything into the table, I have double checke the table name is correct.What could cause that problem


    Posted By: pmormr
    Date Posted: 02 July 2003 at 1:32pm
    yo!!! wake up you stil don't have the fields. replace the line of code with the approperate fields

    insert into table (field1,field2,field3) values (value1,value2,value3)

    -------------
    Paul A Morgan

    http://www.pmorganphoto.com/" rel="nofollow - http://www.pmorganphoto.com/



    Print Page | Close Window

    Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
    Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net