Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing records, best approach???

Status
Not open for further replies.

aolb

Programmer
Apr 16, 2002
180
GB
For the first time I have to take the data entered on a screen and write it to a record. I can think of a few ways of doing this but what is the best approach?

I am using ASP and SQL Server and I have VB if needed.
 
There are, as always, several ways to accomplish this. One way is to create a stored procedure on your SQL Server, and pass it your data from the web-page. Another is to create and populate a recordset in your ASP, and then update your database with it.

I guess it all comes down to preference. Personally, I prefer the latter. :)

Here's an example on how to build the recordset. It's not ASP, but it's generally the same:

Palooka
 
Basically whatever way I do this I will need a second ASP page to take the data from screen produced by the first ASP page and then write the data to a record.
 
Not necessarely. That tends to give you a whole lot of files to manage.

To avoid that, you can have the page post to itself:
Code:
<form name=&quot;myForm&quot; action=&quot;<%= Request.ServerVariables(&quot;SCRIPT_NAME&quot;)%>&quot; method=&quot;post&quot;>

Thus you can have your ASP to check wether it should build your web-page as usual, or process the form and build a recordset:
Code:
if Request.ServerVariables(&quot;Request_Method&quot;) = &quot;POST&quot; Then
   'Request data from form
   'Build recordset
   'Update database
else
   'Build web page
end if

Palooka
 
I wrote a (very) commented example of doing something similar in the FAQs. The page submits back to itselkf for all DB submissions (Insert, Update, And delete) using flags to control what action to tak and whether to just list the results or do another transaction, like add a record, and then list the results.
The code is downloadable for the commented and uncommented version, the db is access (yuck) but the same logic will work for any database. ASP 102 FAQ
-Tarwn ------------ My Little Dictionary ---------
Reverse Engineering - The expensive solution to not paying for proper documentation
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top