Creating a Server Component with VB - Redesig…
2008-04-10 03:07:30来源:互联网 阅读 ()
By Doug Dean Rating: 4.1 out of 5
Rate this article print this article
Introduction
This is part 2 of an article that demonstrates how to design a maintainable server-side DLL that can be called from an ASP page and rendered in any browser. This part shows how to apply the ideas discussed in Part 1 (see http://www.15seconds.com/Issue/010730.htm). It will cover different aspects of retrieving data from a database and how best to work with that data within a Visual Basic (VB) DLL so that the method string that is returned contains a structure ready to be rendered within a browser.
Returning a compact browser-ready string from a component can be very convenient for the end developer, although not without issue. Debates regarding the sanctity of the separation between presentation and business tiers are not merely academic. I have found that speed can be as important as maintenance, especially with Internet applications running on servers. Just as in the normalization process related to database table design, sometimes allowing a little practical redundancy goes a long way in relieving processing burdens and speeding up transactions. In the case of populating an HTML TABLE with values from a database in an ASP/VB environment, many different options are open to the programmer, as mentioned in the first part of this article.
The code demonstrated here will construct fully structured HTML TABLE data records encapsulated between <TD></TD> tags within the VB code itself. The values used to construct this return string, containing ready-to-render HTML TABLE data, will come from three sources. The data contained within the VB-constructed HTML TABLE tags will be stored within a database table. Values that deal with controlling the immediate retrieval of this data, such as which database record to display, will be sent to the VB code via method parameters that originate from the ASP file that calls the method. Presentation data, the HTML TABLE TD and FONT tag values, will be retrieved from a separate database table, although default values for these variables will also be written into the VB code itself.
Because of the "code application" nature of this second article, there''''s much more example code than in the first article. I''''ve tried to simplify the entirety of the example code as much as possible without omitting any of the processes that this article is attempting to exemplify. The difficulty with a program of this complexity is preserving the overall conceptual nature of a significant amount of code while presenting it in smaller, topical sections. Most of the following example code sections can be placed within VB and run "as-is," although some example code fragments are also included and are labeled as such. Once the functioning of a section of example code is explained, any further code added to the same example code will be highlighted in bold so that you can more easily see the newly introduced code and how it functions within the context of previously discussed code.
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 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.
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash