Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 Other Development Tools
 not sure of title really, asp sql stuff!

Author  Topic 

newbie sql
Starting Member

12 Posts

Posted - 2004-09-02 : 05:04:08
Hey,

I'm displaying some records from a database in a while loop. I have a link beside each item which *should* allow the item to be removed and another link whichc *should* allow the item to be deleted and a new one inserted. What I want to do is allow the delete link to be clicked, the sql statement executed and the page refreshed with the item removed. Here is what I have to start with:

	<tr> <%while not rs1.eof or rs1.bof %>

<td width="35%">Item</td>
<td width="5%"> </td>
<td width="100%">
<%= Rs1("cat_ref")%> 
<%= Rs1("descrip")%> 
<%= Rs1("cat_type")%> 
<%= Rs1("contract")%> 
£<%= Rs1("cost_price")%> 
<%= Rs1("supplier_name")%> 

</td>
</tr>

<tr>
<td width="35%"> </td>
<td width="5%"> </td>
<td align="left">
<a style="font-family:verdana;font-size:80%" href="remove.asp?cat_ref=rs1("cat_ref")"> remove item</a> 
<a style="font-family:verdana;font-size:80%" href="change.asp"> change item</a> 
</td>
</tr>

<tr>
<td width="35%"> </td>
<td width="5%"> </td>
<td width="65%">  </td>
</tr>

<%
rs1.movenext
wend
%>


I did something similar before but with a dropdown using the onchange function in vbscript. I'd like to stick to vbscript but I'm not sure what to do.... any help would be very much appreciated. Thanks :)

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-09-02 : 05:18:35
well u need to reload the page (of course :)) and then there are three ways (i can remember for now) u can do it:
1. add a new parameter to the query string, *and at the start of the page check if it exists delete the record.
2. save id in session and do the same as in 1*
3. save id in the hidden textbox and same as 1*

Go with the flow & have fun! Else fight the flow :)
Go to Top of Page

newbie sql
Starting Member

12 Posts

Posted - 2004-09-02 : 05:23:16
How do I reload the page when the link is clicked?
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-09-02 : 05:46:19
request.redirect (url)

Go with the flow & have fun! Else fight the flow :)
Go to Top of Page

newbie sql
Starting Member

12 Posts

Posted - 2004-09-02 : 06:33:57
hey thanks for that.... I assume u mean response.redirect?

I'm doing this
<%
quote_id = request.querystring("quote_id")
response.redirect("editquote.asp?quote_id=quote_id")
%>

and then in editquote i'm doing:

quote_id = request.querystring("quote_id")

SQLStmt = "SELECT * from quote, quoteitem "
SQLStmt = SQLStmt & "WHERE quoteitem.quote_id = quote.quote_id and quote.quote_id = convert(int,'" "e_id& "')"
rs.open SQLStmt, conn
but I get an error
Syntax error converting the varchar value 'quote_id' to a column of data type int
even although the page worked when getting the quote_id from another page in the same way.....
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-09-02 : 07:25:14
yes sorry i meant response...

try this:
"WHERE quoteitem.quote_id = quote.quote_id and quote.quote_id = " & e_id

because if it is an int there is no need for conversion. if its not, then u cant convert it to int in sql.


Go with the flow & have fun! Else fight the flow :)
Go to Top of Page

mr_mist
Grunnio

1870 Posts

Posted - 2004-09-02 : 07:39:18
I'd also change

quote_id = request.querystring("quote_id")

to

quote_id = cint (request.querystring("quote_id"))

Though I should add the usual disclaimer that it's a bad idea to directly put your query string entries into a sql statement without proper parsing/checking beforehand, and you really should be using stored procs for this. And select * is not that great, either ;)


-------
Moo. :)
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2004-09-02 : 09:52:17
look at your HTML that your ASP page generates. It is constructing a URL passing in the value that you wish? I suspect not.

In your very first post,


<a style="font-family:verdana;font-size:80%" href="remove.asp?cat_ref=rs1("cat_ref")"> remove item</a>


needs to be changed to:


<a style="font-family:verdana;font-size:80%" href="remove.asp?cat_ref=<%=rs1("cat_ref")%>"> remove item</a>


I think you were passing in =rs1("cat_ref") as a parameter to your next page, as opposed to evaluatinng that expression and passing in the RESULT.

Does this help?

Always feel free to code dummy pages that just output the values of all paramters passed, using simple response.write() commands. Always give yourself feedback while writing code in the form of little bits of extra output here and there showing the values of variables and whatnot.

- Jeff
Go to Top of Page
   

- Advertisement -