| Author |
Topic |
|
steelkilt
Constraint Violating Yak Guru
255 Posts |
Posted - 2002-12-30 : 15:27:44
|
| I do a lot of SQL table updating via ASP pages, allowing users to pass search criteria along with SQL table names in order to serve up the correct ASP update page.I find myself in the situation now where I need to add a third ASP processing script at the end of the line. The idea here is my first ASP page is the form for data input. I pass the form values from the first form to the second ASP script, which runs a quick SQL Select statement to see if a recordset is returned on the specified table. If recordset is returned, user gets "record already in database" type message. If no recordset is returned, I want to response.redirect my users to the proper update page, BUT I need to carry the form values from the first form in the series to the third form in the series.In the past I have used conditional statements on the second ASP script in the series to send users to the proper chunk of code, but in the current case this would result in a MILES LONG asp page that I'd rather not deal with. Any ideas on how to execute this? thx |
|
|
tool
Starting Member
26 Posts |
Posted - 2002-12-30 : 16:14:00
|
| Why not do it all with one asp page and one sproc. Set up a sproc that accepts the insert values as params and return a param signifying if the record already exists. In the sproc first test if the record exists, if so set return param to true, if the record doesn't exist set the return param to false and perform the insert. In your asp page simply call the sproc then test the return param to determine what the page should display.I like to make my asp pages self-posting, I think it makes working with the posted values a lot easier because you don't have to worry about moving them from page to page. |
 |
|
|
steelkilt
Constraint Violating Yak Guru
255 Posts |
Posted - 2002-12-30 : 16:41:38
|
| thx. good idea. |
 |
|
|
ValterBorges
Master Smack Fu Yak Hacker
1429 Posts |
Posted - 2002-12-30 : 17:40:15
|
| Two other options:1.If you're form is small you could also pass the values via the querystring. Careful, querystring length is limited I believe to 2K.Ex: Response.Redirect "abc.asp?var1=val1;var2=val2"2.Other method I have use to simulate application type behavior is to have a hidden data communication frame in my html pages. When the first form is submitted you could run some javascript that submits the form through the hidden frame. Next the asp that processes that form would generate some Javascript variables, object which could bring back data, error codes, etc... and also an onload callback function. Basically when the page is done loading it would notify some other function that the action has been completed at which point the function that was notified would run some logic to test the returned data, error codes, etc... and act accordingly. In your case that would mean checking a return code and redirecting to the update page using javascript. |
 |
|
|
steelkilt
Constraint Violating Yak Guru
255 Posts |
Posted - 2002-12-30 : 17:58:08
|
| Valter,Thanks. It occurs to me now that your technique will be better for me as I'm doing updates where I have to do the following:1. Check for existence of record in DB2. If record exists, load record to update form.3. Post updates to DBI'm passing two variables, so this is straightforward.Question: is that all the code that's needed to pass the querystring? It appears I just need to pass to the third ASP page the string variables I've already captured in the second ASP form?thx |
 |
|
|
GreatInca
Posting Yak Master
102 Posts |
Posted - 2002-12-30 : 20:06:16
|
| I always do[FORM sub]Provided a PK?Yes: Query Record Record Exists? Yes: Extract record No: Nuke the provided PK (st var to 0) Set field vars to blank/0No: Set field vars to blank/0(Put PK var in a hidden field)[SUBMIT SUB]Extract formExecute SPSP inserts/updates depending on whether PK value was provided by form. |
 |
|
|
ValterBorges
Master Smack Fu Yak Hacker
1429 Posts |
Posted - 2002-12-31 : 00:11:55
|
quote: Question: is that all the code that's needed to pass the querystring? It appears I just need to pass to the third ASP page the string variables I've already captured in the second ASP form?
Yes, you're correct.Also you don't need to recode your asp if you access your response object as such.Request("var1")instead of Request.Form("") or Request.QueryString("") by default the object will search through it's collections and try to find the first match in any collection. This works nicely if you want to call the page by submitting a form sometimes and by passing a querystring other times.For better performance however you would want to use Request.QueryString() |
 |
|
|
p2bl
Yak Posting Veteran
54 Posts |
Posted - 2002-12-31 : 01:54:31
|
| and there's a new method for the "Server" object in IIS5.0,server.execute(another ASP page),the "another ASP page" will inherit all request var,and the ASP page that contains it will execute after "Server.execute" done.By the way,r u doing a search engine?I am fond of it,but do not know how to build a search engine that could serve lots of simultaneous vistors?Can I rely on SQL Server or other RDBMS?========================look! |
 |
|
|
ValterBorges
Master Smack Fu Yak Hacker
1429 Posts |
|
|
tool
Starting Member
26 Posts |
Posted - 2002-12-31 : 11:17:08
|
quote: Thanks. It occurs to me now that your technique will be better for me as I'm doing updates where I have to do the following: 1. Check for existence of record in DB 2. If record exists, load record to update form. 3. Post updates to DB
I guess I don't quite understand why you would prefer to use a method requiring 3 asp pages and 2 sprocs/sql stmts over a method that uses 1 asp page and 1 sproc.Example: CREATE PROCEDURE MyProc @KeyVal int, @Value varchar(50), @Exists bit OUTPUTASIF EXISTS(SELECT 1 FROM MyTable WHERE KeyVal=@KeyVal) SET @Exists=1ELSEBEGIN SET @Exists=0 INSERT INTO MyTable(KeyVal,Value) VALUES(@KeyVal,@Value)ENDGO To me the latter method seems much clearer and requires less network overhead. Is there something I'm missing?Just curious... |
 |
|
|
steelkilt
Constraint Violating Yak Guru
255 Posts |
Posted - 2002-12-31 : 15:23:32
|
| I'm doing an update, not an insert, so I have to first locate the proper table via a check for unique record, then I must load the data to an UPDATE ASP form, then I must post the data back to the DB via UPDATE "action" ASP script. |
 |
|
|
steelkilt
Constraint Violating Yak Guru
255 Posts |
Posted - 2002-12-31 : 16:31:51
|
| Valter,I can pass the querystring to the third ASP successfully, with the url listing in the address bar of the third ASP as:http://mysite/update.asp?'1.1'However, this third form is not picking up the passed string for use in the database query that is supposed to load the update. Examples of my code:FIRST ASP:A text box and a dropdown. Both values passed to second asp with this action tag:<form action="frontdoor_action.asp" method="POST" name="frontdoor">SECOND ASP (frontdoor_action):================================================Sets the two variables...strFamily = cStr(Request.Form("Family"))strTableChoice = cStr(Request.Form("TableChoice"))=====================================================TableChoice value determines which SQL block is run...SQL is run -- SELECT query to see if record already in table...Record found in table, so we redirect...Response.Redirect("update.asp?'"&strFamily&"'")THIRD ASP:Requests the needed string, then runs SQL query which is supposed to fetch the record from the DB. This is not happening, recordset is empty, I presume because I'm not passing the string properly to the SQL statement. Any ideas? thx.=================================================<%'GET FAMILY STRING FROM SECOND ASP Request("strFamily")'SELECT RECORD FROM TABLE WHERE FAMILY IS FOUNDSQL = "SELECT * FROM SUMMARY WHERE FAMILY='"&strFamily&"';"SET DbObj= Server.CreateObject("ADODB.Connection")DbObj.Open "DSN=junk"SET oRs = DbObj.Execute(SQL)'POPULATE THE FORM WITH DATA'FROM THE USER'S RECORD.%> |
 |
|
|
ValterBorges
Master Smack Fu Yak Hacker
1429 Posts |
Posted - 2002-12-31 : 18:10:21
|
| The querystring should look likeResponse.Redirect("update.asp?Family=" & Server.UrlEncode(strFamily)) In the other asp you need.strFamily = Request("Family") |
 |
|
|
steelkilt
Constraint Violating Yak Guru
255 Posts |
Posted - 2003-01-02 : 09:03:30
|
| Thanks, works beautifully. Got my variables and values mixed up and had no idea about URL Encode. |
 |
|
|
|