By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,291 Members | 3,120 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,291 IT Pros & Developers. It's quick & easy.

Adding rows to database table thro ASP

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.