Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - insert into table
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

insert into table

 Post Reply Post Reply
Author
beginner View Drop Down
Newbie
Newbie


Joined: 22 May 2003
Status: Offline
Points: 8
Post Options Post Options   Thanks (0) Thanks(0)   Quote beginner Quote  Post ReplyReply Direct Link To This Post Topic: insert into table
    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

 


Back to Top
ljamal View Drop Down
Mod Builder Group
Mod Builder Group


Joined: 16 April 2003
Status: Offline
Points: 888
Post Options Post Options   Thanks (0) Thanks(0)   Quote ljamal Quote  Post ReplyReply Direct Link To This Post 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.

Edited by ljamal
Back to Top
beginner View Drop Down
Newbie
Newbie


Joined: 22 May 2003
Status: Offline
Points: 8
Post Options Post Options   Thanks (0) Thanks(0)   Quote beginner Quote  Post ReplyReply Direct Link To This Post 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
  • Back to Top
    ljamal View Drop Down
    Mod Builder Group
    Mod Builder Group


    Joined: 16 April 2003
    Status: Offline
    Points: 888
    Post Options Post Options   Thanks (0) Thanks(0)   Quote ljamal Quote  Post ReplyReply Direct Link To This Post 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")&"')"
    Back to Top
    beginner View Drop Down
    Newbie
    Newbie


    Joined: 22 May 2003
    Status: Offline
    Points: 8
    Post Options Post Options   Thanks (0) Thanks(0)   Quote beginner Quote  Post ReplyReply Direct Link To This Post 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
    Back to Top
    pmormr View Drop Down
    Senior Member
    Senior Member


    Joined: 06 January 2003
    Location: United States
    Status: Offline
    Points: 1479
    Post Options Post Options   Thanks (0) Thanks(0)   Quote pmormr Quote  Post ReplyReply Direct Link To This Post 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)
    Back to Top
     Post Reply Post Reply

    Forum Jump Forum Permissions View Drop Down

    Forum Software by Web Wiz Forums® version 12.08
    Copyright ©2001-2026 Web Wiz Ltd.


    Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
    About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

    Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
    Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

    Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

    Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.