 |
| Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

March 8th, 2005, 07:55 AM
|
|
Registered User
|
|
Join Date: Mar 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
How can I update 2 rows in one column in SQL table
please help as I have been stuck for days.
I want to update 2 lines in an SQL table
The form.asp source, says :
1. <input type="Hidden" name= "ID" value="1"><input type="text" name= "state" value="free">
2. <input type="Hidden" name= "ID" value="2"><input type="text" name= "state" value="busy">
The from_action.asp says
<%p_ID= request.form("p_ID")
p_state= request.form("p_state")
SQL Text="update tableState set state='"& p_state &"' where ID= '"& p_ID &"' select * from tableState"
But the <% response.write SQL Text%> command gives me the following response :
UPDATE tableState Set State='free,busy' WHERE ID='1,2' select * from tableState
If I add
<% for each p_ID in request.form("p_ID")%>
<% Next %>
I get two lines of UPDATES, but still the 'free, busy' in each.
Thank you in advance for you help
Sylvie
|
|

March 8th, 2005, 09:30 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
|
|
you've separated the 2 IDs by using a For Each, you can also separate the States by using a subindex: Request.Form("p_state")(1) and Request.Form("p_state")(2) (I can't remember if the first one is 1 or 0). So you can just add an index to your loop:
idx=1 ' or maybe 0
for each p_ID in request.form("p_ID")
p_state = Request.Form("p_state")(idx)
...
idx=idx+1
Next
(In your SQL you don't need the ' around the ID if its numeric data.)
hth
Phil
|
|

March 9th, 2005, 06:37 AM
|
|
Registered User
|
|
Join Date: Mar 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thank you very very much, the answer fitted perfectly to the question, However, I am since stuck because the form is supposed to display a radio button
Such as :
1. <input type="Hidden" name= "ID" value="A1">free <input type="radio" name= "state" value="free"checked> busy <input type="radio" name= "state" value="busy">
2. <input type="Hidden" name= "ID" value="A2">free <input type="radio" name= "state" value="free"> busy <input type="radio" name= "state" value="busy" checked>
The problem arrises in two ways :
First : the two separate radio buttons act as one radio button !
Second : In my form_action.asp, i get an error message saying that the index cannot function ; i understand why, but I do not know what to do
DO you think you could also help me on those two problems ?
merci beaucoup in advance, Sylvie
|
|

March 9th, 2005, 09:04 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
|
|
I am confused now. If you want 2 separate sets of radio buttons you need to use a different name for each set. I am wondering now why you have 2 ID fields with the same name...
|
|

March 9th, 2005, 10:27 AM
|
|
Registered User
|
|
Join Date: Mar 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thank you for your patience.
I understand for the radio buttons.
I have 2 ID fields with the same name, because in the reality the form comes from a SQL Select statement, and thus says :
<% Set AnSet= Bona_data.Execute("Select....
Do while not AnSet.EOF%>
<Form name="FreeBusy" Method="post" action"form_action.asp">
<% IF <%=AnSet("state")%>= "free" then%>
<Input type "Hidden" Name="p_ID" value="<%=AnSet("ID")%>"> <B><%=AnSet("ID")%></B> is <input type="radio" name= "p_state" value="free" checked> busy <input type="radio" name= "state" value="busy">
<%else%>
<Input type "Hidden" Name="p_ID" value="<%=AnSet("ID")%>"> <B><%=AnSet("ID")%></B> is <input type="radio" name= "p_state" value="free"> busy <input type="radio" name= "state" value="busy" checked>
<%end if%>
<% AnSet.Movenext%>
THanks
Syl
|
|

March 9th, 2005, 10:54 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
|
|
OK I understand. you need a way to associate each set of radio buttons with its ID - can you use the value of the ID as part of the name of the radio? So in form.asp the name of each radio is: <input type="radio" name="state<%=AnSet("ID")%>" ...>
Then when you read the values in form_action.asp you can do this:
For Each p_ID in Request.Form("p_ID")
state = Request.Form("state" & p_ID)
...
Next
|
|

March 9th, 2005, 11:13 AM
|
|
Registered User
|
|
Join Date: Mar 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thank you, I will try this eve. But I am already sure it will function, as I had tried everything but not this little & p_ID in state = Request.Form("state" & p_ID)
I will try
Thanks Sylvie
|
|
 |