469,352 Members | 2,154 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,352 developers. It's quick & easy.

Adding rows to database table thro ASP

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
('B-096','Hihihihihi','hello','Book','07/18/04')"
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
appreciated.

Thanks in advance,
Vasanth
-----------------------------
<%
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)&""""
next
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
('"&session("index")&"','"&title&"','"&author&"',' "&session("itemtype")&"','
"&date&"')"
strQ = "INSERT into library (index,title,author,itemtype,createdate) VALUES
('B-096','Hihihihihi','hello','Book','07/18/04')"
objRst.Open strQ
Set objRst = nothing
objConnect.Close
Set objConnect = nothing
%>
<html>
<head>
<title>
</title>
</head>
<body>
Library Item, <%=session("index")%> has been created on <%=date%>.
</body>
</html>
Jul 19 '05 #1
2 1253
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
off-topic.
vasanth kumar wrote:
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 ('B-096','Hihihihihi','hello','Book','07/18/04')"
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
appreciated.

Thanks in advance,
Vasanth
-----------------------------
<%
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)&""""
next
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
('"&session("index")&"','"&title&"','"&author&"',' "&session("itemtype")&"',' "&date&"')"
strQ = "INSERT into library (index,title,author,itemtype,createdate)
VALUES ('B-096','Hihihihihi','hello','Book','07/18/04')"
objRst.Open strQ
Set objRst = nothing
objConnect.Close
Set objConnect = nothing
%>
<html>
<head>
<title>
</title>
</head>
<body>
Library Item, <%=session("index")%> has been created on <%=date%>.
</body>
</html>


--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 19 '05 #2
Check for reserved words and use ## for dates....

"vasanth kumar" <va***********@eds.com> wrote in message
news:uZ**************@tk2msftngp13.phx.gbl...
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 ('B-096','Hihihihihi','hello','Book','07/18/04')"
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
appreciated.

Thanks in advance,
Vasanth
-----------------------------
<%
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)&""""
next
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 ('"&session("index")&"','"&title&"','"&author&"',' "&session("itemtype")&"',' "&date&"')"
strQ = "INSERT into library (index,title,author,itemtype,createdate) VALUES ('B-096','Hihihihihi','hello','Book','07/18/04')"
objRst.Open strQ
Set objRst = nothing
objConnect.Close
Set objConnect = nothing
%>
<html>
<head>
<title>
</title>
</head>
<body>
Library Item, <%=session("index")%> has been created on <%=date%>.
</body>
</html>

Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Viorel | last post: by
3 posts views Thread by Jim Heavey | last post: by
3 posts views Thread by Ankit Aneja | last post: by
10 posts views Thread by Trevor | last post: by
2 posts views Thread by Niels Jensen | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.