Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access_asp thread: add/delete records with action switch


Message #1 by "Lori Bannon" <lori@s...> on Wed, 11 Dec 2002 22:57:45
Hi all,

I'm trying to add and delete records with an action switch and I can't 
remember how to...need some help.

Here's my proc code:

<%@ Language = "VBScript"%>
<%
'Declare all local variables
dim conn
dim rs
dim strconn
dim strsql
dim lAction

lAction = Request.Form("Action")

strsql = ""
'set connection string to local variable-I use a DSN-less connection
strconn = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath
("../data/database.mdb")

'Set connection object 
set conn = server.createobject("adodb.connection")
conn.open strconn

if lAction = Add then

strSQL = "INSERT INTO tblList(tblName,tblDesc,tblPrice) Values('" & request
("frmName") & "', '" & request("frmDesc") & "', '" & request("frmPrice") 
& "')"

elseif lAction = Delete then

strSQL = "DELETE FROM tblList(tblName,tblDesc,tblPrice) Values('" & request
("frmName") & "', '" & request("frmDesc") & "', '" & request("frmPrice") 
& "')"

conn.execute(strSQL)
end if

Response.Redirect "index2.asp"

conn.close
set conn = nothing
%>

Here's my form code (minus the HTML to easier reading):

<form name="addForm" method="post" action="addForm.asp">
<input type="text" name="frmName" size="25" maxlength="25
<input type="text" name="frmDesc" size="25" maxlength="25">
<input type="text" name="frmPrice" size="25" maxlength="25">

<input type=submit name=Action value=Add>&nbsp;&nbsp;&nbsp;<input 
type=submit name=Action value=Delete>
</form>


thanks ahead of time
Lori
Message #2 by Karri Peterson <KPeterson@C...> on Wed, 11 Dec 2002 16:50:36 -0600
If this is the html in your form, you have two form fields with the same
name, and your value coming into your proc code probably reflects both of
the fields.  

Karri

-----Original Message-----
From: Lori Bannon [mailto:lori@s...]
Sent: Wednesday, December 11, 2002 4:58 PM
To: Access ASP
Subject: [access_asp] add/delete records with action switch


Hi all,

I'm trying to add and delete records with an action switch and I can't 
remember how to...need some help.

Here's my proc code:

<%@ Language = "VBScript"%>
<%
'Declare all local variables
dim conn
dim rs
dim strconn
dim strsql
dim lAction

lAction = Request.Form("Action")

strsql = ""
'set connection string to local variable-I use a DSN-less connection
strconn = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath
("../data/database.mdb")

'Set connection object 
set conn = server.createobject("adodb.connection")
conn.open strconn

if lAction = Add then

strSQL = "INSERT INTO tblList(tblName,tblDesc,tblPrice) Values('" & request
("frmName") & "', '" & request("frmDesc") & "', '" & request("frmPrice") 
& "')"

elseif lAction = Delete then

strSQL = "DELETE FROM tblList(tblName,tblDesc,tblPrice) Values('" & request
("frmName") & "', '" & request("frmDesc") & "', '" & request("frmPrice") 
& "')"

conn.execute(strSQL)
end if

Response.Redirect "index2.asp"

conn.close
set conn = nothing
%>

Here's my form code (minus the HTML to easier reading):

<form name="addForm" method="post" action="addForm.asp">
<input type="text" name="frmName" size="25" maxlength="25
<input type="text" name="frmDesc" size="25" maxlength="25">
<input type="text" name="frmPrice" size="25" maxlength="25">

<input type=submit name=Action value=Add>&nbsp;&nbsp;&nbsp;<input 
type=submit name=Action value=Delete>
</form>


thanks ahead of time
Lori
Message #3 by "Lori Bannon" <lori@s...> on Thu, 12 Dec 2002 15:18:34
Not quite sure what you mean? The two submit buttons have the same 
name=action and that part works. If I comment out the database queries and 
just do a response.write = laction then it gives me add or delete 
depending on which submit button I click. So I know that much is working. 
Also, I know the database is open because I don't get any errors. What 
isn't working are the queries because nothing happens.





> If this is the html in your form, you have two form fields with the same
name, and your value coming into your proc code probably reflects both of
the fields.  

Karri

-----Original Message-----
From: Lori Bannon [mailto:lori@s...]
Sent: Wednesday, December 11, 2002 4:58 PM
To: Access ASP
Subject: [access_asp] add/delete records with action switch


Hi all,

I'm trying to add and delete records with an action switch and I can't 
remember how to...need some help.

Here's my proc code:

<%@ Language = "VBScript"%>
<%
'Declare all local variables
dim conn
dim rs
dim strconn
dim strsql
dim lAction

lAction = Request.Form("Action")

strsql = ""
'set connection string to local variable-I use a DSN-less connection
strconn = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath
("../data/database.mdb")

'Set connection object 
set conn = server.createobject("adodb.connection")
conn.open strconn

if lAction = Add then

strSQL = "INSERT INTO tblList(tblName,tblDesc,tblPrice) Values('" & request
("frmName") & "', '" & request("frmDesc") & "', '" & request("frmPrice") 
& "')"

elseif lAction = Delete then

strSQL = "DELETE FROM tblList(tblName,tblDesc,tblPrice) Values('" & request
("frmName") & "', '" & request("frmDesc") & "', '" & request("frmPrice") 
& "')"

conn.execute(strSQL)
end if

Response.Redirect "index2.asp"

conn.close
set conn = nothing
%>

Here's my form code (minus the HTML to easier reading):

<form name="addForm" method="post" action="addForm.asp">
<input type="text" name="frmName" size="25" maxlength="25
<input type="text" name="frmDesc" size="25" maxlength="25">
<input type="text" name="frmPrice" size="25" maxlength="25">

<input type=submit name=Action value=Add>&nbsp;&nbsp;&nbsp;<input 
type=submit name=Action value=Delete>
</form>


thanks ahead of time
Lori
Message #4 by "Lori Bannon" <lori@s...> on Thu, 12 Dec 2002 15:40:06
I got it to work - The switch code should have been:

if lAction ="Add" then instead of if lAction = Add then

DOH!

> Not quite sure what you mean? The two submit buttons have the same 
n> ame=action and that part works. If I comment out the database queries 
and 
j> ust do a response.write = laction then it gives me add or delete 
d> epending on which submit button I click. So I know that much is 
working. 
A> lso, I know the database is open because I don't get any errors. What 
i> sn't working are the queries because nothing happens.

> 

> 

> > If this is the html in your form, you have two form fields with the 
same
n> ame, and your value coming into your proc code probably reflects both of
t> he fields.  

> Karri

> -----Original Message-----
F> rom: Lori Bannon [mailto:lori@s...]
S> ent: Wednesday, December 11, 2002 4:58 PM
T> o: Access ASP
S> ubject: [access_asp] add/delete records with action switch

> 
H> i all,

> I'm trying to add and delete records with an action switch and I can't 
r> emember how to...need some help.

> Here's my proc code:

> <%@ Language = "VBScript"%>
<> %
'> Declare all local variables
d> im conn
d> im rs
d> im strconn
d> im strsql
d> im lAction

> lAction = Request.Form("Action")

> strsql = ""
'> set connection string to local variable-I use a DSN-less connection
s> trconn = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath
(> "../data/database.mdb")

> 'Set connection object 
s> et conn = server.createobject("adodb.connection")
c> onn.open strconn

> if lAction = Add then

> strSQL = "INSERT INTO tblList(tblName,tblDesc,tblPrice) Values('" & 
request
(> "frmName") & "', '" & request("frmDesc") & "', '" & request("frmPrice") 
&>  "')"

> elseif lAction = Delete then

> strSQL = "DELETE FROM tblList(tblName,tblDesc,tblPrice) Values('" & 
request
(> "frmName") & "', '" & request("frmDesc") & "', '" & request("frmPrice") 
&>  "')"

> conn.execute(strSQL)
e> nd if

> Response.Redirect "index2.asp"

> conn.close
s> et conn = nothing
%> >

> Here's my form code (minus the HTML to easier reading):

> <form name="addForm" method="post" action="addForm.asp">
<> input type="text" name="frmName" size="25" maxlength="25
<> input type="text" name="frmDesc" size="25" maxlength="25">
<> input type="text" name="frmPrice" size="25" maxlength="25">

> <input type=submit name=Action value=Add>&nbsp;&nbsp;&nbsp;<input 
t> ype=submit name=Action value=Delete>
<> /form>

> 
t> hanks ahead of time
L> ori
-> --
C> hange your mail options at 
t> o unsubscribe send a blank email to 
Message #5 by "Thomas, Dean" <Dean.Thomas@u...> on Thu, 12 Dec 2002 11:59:52 -0500
I noticed quotes missing on the If-Then-Else statement...

i.e. if lAction = "Add" then

All for now.
Dean

-----Original Message-----
From: Lori Bannon [mailto:lori@s...]
Sent: Thursday, December 12, 2002 10:19 AM
To: Access ASP
Subject: [access_asp] RE: add/delete records with action switch


Not quite sure what you mean? The two submit buttons have the same 
name=action and that part works. If I comment out the database queries and 
just do a response.write = laction then it gives me add or delete 
depending on which submit button I click. So I know that much is working. 
Also, I know the database is open because I don't get any errors. What 
isn't working are the queries because nothing happens.





> If this is the html in your form, you have two form fields with the same
name, and your value coming into your proc code probably reflects both of
the fields.  

Karri

-----Original Message-----
From: Lori Bannon [mailto:lori@s...]
Sent: Wednesday, December 11, 2002 4:58 PM
To: Access ASP
Subject: [access_asp] add/delete records with action switch


Hi all,

I'm trying to add and delete records with an action switch and I can't 
remember how to...need some help.

Here's my proc code:

<%@ Language = "VBScript"%>
<%
'Declare all local variables
dim conn
dim rs
dim strconn
dim strsql
dim lAction

lAction = Request.Form("Action")

strsql = ""
'set connection string to local variable-I use a DSN-less connection
strconn = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath
("../data/database.mdb")

'Set connection object 
set conn = server.createobject("adodb.connection")
conn.open strconn

if lAction = Add then

strSQL = "INSERT INTO tblList(tblName,tblDesc,tblPrice) Values('" & request
("frmName") & "', '" & request("frmDesc") & "', '" & request("frmPrice") 
& "')"

elseif lAction = Delete then

strSQL = "DELETE FROM tblList(tblName,tblDesc,tblPrice) Values('" & request
("frmName") & "', '" & request("frmDesc") & "', '" & request("frmPrice") 
& "')"

conn.execute(strSQL)
end if

Response.Redirect "index2.asp"

conn.close
set conn = nothing
%>

Here's my form code (minus the HTML to easier reading):

<form name="addForm" method="post" action="addForm.asp">
<input type="text" name="frmName" size="25" maxlength="25
<input type="text" name="frmDesc" size="25" maxlength="25">
<input type="text" name="frmPrice" size="25" maxlength="25">

<input type=submit name=Action value=Add>&nbsp;&nbsp;&nbsp;<input 
type=submit name=Action value=Delete>
</form>


thanks ahead of time
Lori

  Return to Index