Adding rows to database table thro ASP

Discussion in 'ASP General' started by vasanth kumar, Jul 18, 2004.

  1. Hi,
    I want to add a row to library table. Table has total 7 fields. But I
    want to create the new row with 5 field data. When I run the following query
    in MS Access
    strQ = "INSERT into library (index,title,author,itemtype,createdate) VALUES
    It successfully adds the row. But same thing I am trying with the following
    ASP code. It gives error, saying syntax error in INSERT into statement.

    Can anybody suggest me, what is wrong in my code below. Any help is

    Thanks in advance,
    option explicit
    Response.ExpiresAbsolute = "January 1, 2003"
    Dim path, mdbFilePath, sPos, objConnect, objRst, strQ, x
    for each x in Request.Form
    execute x & "="""&Request(x)&""""
    path = Request.ServerVariables("PATH_TRANSLATED")
    sPos = InStr(path, "library\newupdate.asp")
    if sPos = 0 then
    sPos = InStr(path, "library/newupdate.asp")
    end if
    mdbFilePath = Left(path, sPos-1) & "library.mdb"
    Set objConnect = Server.CreateObject("ADODB.Connection")
    objConnect.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
    mdbFilePath & ";"
    Set objRst = Server.CreateObject("ADODB.Recordset")
    Set objRst.ActiveConnection = objConnect
    'strQ = "INSERT into library (index,title,author,itemtype,createdate) VALUES
    strQ = "INSERT into library (index,title,author,itemtype,createdate) VALUES
    objRst.Open strQ
    Set objRst = nothing
    Set objConnect = nothing
    Library Item, <%=session("index")%> has been created on <%=date%>.
    vasanth kumar, Jul 18, 2004
    1. Advertisements

  2. You (and we) cannot debug your sql statement without knowing what it is. Put
    a Response.Write strQ statement into your code so you can see the sql
    statement being generated by your code. Usually, seeing the resulting sql
    statement will highlight where your error is, because you know what it's
    supposed to look like. If not, show it to us.

    Incidently, your query does not return any records, so there is absolutely
    no reason in the world to waste resources and CPU by creating and using a
    recordset object to run this query. A simple

    objConnect.Execute strQ,,129

    will suffice.

    Bob Barrows

    PS. The only relevant newsgroup for this question was .asp.db. You really
    did not have to crosspost it to .general, and .components is definitely
    Bob Barrows [MVP], Jul 18, 2004
    1. Advertisements

  3. vasanth kumar

    dave Guest

    Check for reserved words and use ## for dates....
    dave, Jul 18, 2004
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.