the processes the example application will demonstrate are:
- how to utilize vb method parameter variables sent from a calling asp file.
- vb code that utilizes database transactions.
- vb code that utilizes the getrows() method for retrieving database data.
- how to access data in a variant variable populated by the getrows() method to construct an html-ready formatted string.
- using a database "style table" that can provide a quick way to modify html presentation code.
- the use of string buffering to avoid relying on vb's processing-intense concatenation operator.
- a way to utilize error code to inform the calling asp file when a database record is not successfully retrieved by the vb code.
this is a tall order for a simple example program that's best kept as uncomplicated as possible. the application i picked demonstrates all these processes, although the database transaction code is included without a practical transactional application.
this example application is very limited and lacks vb methods for adding, editing, and deleting the text used in the examples from the database. but then again, this is just enough code to demonstrate the processes needed for you to add these features yourself -- if you feel inclined to do so.
the example vb project, named noteproject, populates an html table record with two table record data areas. the left table record data area contains a list of hyperlinked titles that are stored in a database. in our example code, we'll list some of the topics found in this article. when a user selects any of these title links, database-stored text related to the title will fill the table record area to the right of the titles. so that users won't get confused, we'll provide a way to alter the color of the currently selected title and remove its hyperlink.
the vb code produces html that displays the following table record data:
we'll get the titles from the database using the getrows() method, which conveniently stores our record fields in a multidimensional array. in order to identify which title the user selects, a query string will be attached to the end of each hyperlinked title within the html code. this query string will use the titles' noteid database field value, which is unique for each title.
here's an example of how the title html <a> tags are structured within the table td tags sent back from our vb code to an asp file, which we'll name noteexample.asp. notice that the user must have selected the "buffering" title since <a> tags don't enclose it.
<td width="74" nowrap valign="top">
<font face="verdana" size="1" color="gray">
<a href="noteexample.asp?id=1">intro</a><br>
<a href="noteexample.asp?id=2">style tables</a><br>
<a href="noteexample.asp?id=3">getrows()</a><br>
buffering<br>
<a href="noteexample.asp?id=5">transactions</a><br>
</font>
</td>
the vb code will send back the <td></td> tags along with the tags' content. we'll also provide <font></font> tags, even though the <a> tag will override the font title colors. we can use this to our advantage and set the font color property value to a different color than the page's body link value so that the selected title will display a different color than the linked titles. remember, our vb code will omit the <a></a> tags for the title that is selected by the user, thereby using the font tag color parameter rather than the body link color parameter.
the url for each title will send the user back to the current asp file being displayed -- basically having the asp file call itself when one of the titles is selected. the vb code will also assign a query string named "id" to the end of each titles' url within the <a> tag. the value of the id query string will match each title's unique database record noteid value. every time our example noteexample.asp file is called with an id query string attached to the end of its url, we'll send the id query strings value to the vb code as a method parameter value so that the vb code will know which title was selected. so whether a url with an id query string is called from within the asp file, or from another internet link, the vb code will display the text of the title whose noteid equals the id query string value.
below is the line of asp code that will precede the call to the vb method and assign the "id" query string variable value to a local asp file variable. basically, this line of code sets the local asp variable named aspnoteid to the noteid value of the title that the user selected. we'll then use the aspnoteid variable as a vb method parameter to let the vb method code know which notes' title text to display.
aspnoteid = request.querystring("id")
if the noteexample.asp file is called without a query string named id, then the following line of asp code will set the aspnoteid to the default of 1. sending the vb method code a parameter value that is less than 1, or greater than the number of titles in the database table, would cause an error.
if aspnoteid < 1 then aspnoteid = 1
the right side of our html table re
本文关键:Creating a Server Component with VB - Redesigned
本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)