473,236 Members | 1,786 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,236 software developers and data experts.

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 1362
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Viorel | last post by:
Adding new row with default values. In order to insert programmatically a new row into a database table, without direct "INSERT INTO" SQL statement, I use the well-known DataTable.NewRow,...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
3
by: Robin Thomas | last post by:
I am fairly new to ASP.NET so I think I am missing something fundamental. Anyway, quite often I am pulling data from a database, but then I need to use that data to produce more data. A simple...
1
by: Andrew | last post by:
Hey all, I am very new to ASP.Net (and .Net in general), but that isn't stopping the boss from wanting to begin new projects in it. This latest project has me kinda stumped and after a couple...
3
by: Ankit Aneja | last post by:
I have a strange situation and I have no idea how to solve this. Its a Recruitment Search Page,in the Admin Page, for every button click event the Admin Person has to create a checkbox on the users...
10
by: Trevor | last post by:
Hey, I am trying to do this tutorial on the microsoft site : http://msdn.microsoft.com/library/default.asp? url=/library/en-us/dndotnet/html/usingadonet.asp I can get everything to work up to...
2
by: Niels Jensen | last post by:
I have the following code in a Sub which is called by a do loop statement for each line starting with unit info in an e-mail based game that I play. I'm exctracting the keywords from the text and...
6
by: Rudy | last post by:
Hi all, I know this is easy, just can't seem to get it. I have a windows form, and a text box, with a value already in it. I need to add that value to a table. It's just one value, so the entire...
5
by: joe donnelly | last post by:
I have a couple of questions about recordsets: 1. When a recordset is summoned by the code where does it actually exist and in what form...is it created in the database (data source location)...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.