手机站
网通分站
电信主站
密 码:
用户名:
当前位置 : 主页>网络编程>Asp.Net编程>列表

Creating a Server Component with VB - Redesigned - Part 2

来源:互联网 作者:西部数码 时间:2008-04-10
西部数码-全国虚拟主机10强!40余项虚拟主机管理功能,全国领先!双线多线虚拟主机南北访问畅通无阻!免费赠送企业邮局,.CN域名,自助建站480元起,免费试用7天,满意再付款! P4主机租用799元/月.月付免压金!

The ASP code that calls the VB code:


<HTML><HEAD><TITLE>Note Example</TITLE></HEAD>
<BODY LINK="Navy">

<TABLE BORDER="1" CELLSPACING="0" CELLPADDING="3"><TR>
<!-- === INSTANTIATE CLASS AND CALL ShowNotes() Method === -->

<%
''''///// Set local variables used as VB method parameter variables
aspNoteID = Request.QueryString("ID")
aspStyleID = 0
aspURL = "NoteExample.asp"
aspDbConnectionString = "NotesDSN"

''''///// Set the NoteID to 1 if no ID query string was received
If aspNoteID < 1 Then aspNoteID = 1

''''///// Instantiate the component object
Set objReference = Server.CreateObject("NoteProject.NoteClass")

''''///// Call the components method and store the returned string
strMethodReturn = objReference.ShowNotes(aspNoteID, aspStyleID, aspURL, aspDbConnectionString)

''''///// Send the returned string to the visiting browser
Response.Write(strMethodReturn)

''''///// Clean up
Set objReference = Nothing
%>

<!-- ======================================= -->
</TR></TABLE>

</BODY>
</HTML>

Remember that three of the four method parameters are optional. If the default settings are used, as they are in this article, you can call the VB method by just sending the aspNoteID method parameter and avoid using the other three variables in the ASP file.

Here''''s an example-code fragment that uses the single, nonoptional aspNoteID method parameter.


''''///// Call the components method and store the returned string
strMethodReturn = objReference.ShowNotes(aspNoteID)

The Database Tables

Now that we know how the end product will be structured and how it is to function, we''''ll need to design the database tables that store the data that is used. We''''ll use two database tables contained in an Access database named NoteDb. The first table, named NoteTable, will have three fields:


NoteTable
NoteID		AutoNumber
NoteTitle		Text
NoteText		Memo

Notice that the NoteID field is an AutoNumber type, meaning that Access will assign a unique number to the NoteID field for each NoteTitle or NoteText entered. Also note that the NoteText field is set as a Memo type. This is overkill for this example application since the Memo type can contain a very large amount of text and we''''ll only be using short strings that could be stored in a Text type. But I wanted to show that a Memo type could be used for when you need to store text greater than 256 bytes.

In a real-world application, I would want to use another field name for the primary key AutoNumber field and set a second field named NoteID field set to type Number. When you write code to add note title and text content (not covered in this article), you would then want to use the AutoNumber field''''s value generated by the database to populate the NoteID field with the same value. This provides a little more flexibility since the values of the AutoNumber field can''''t be changed.

We''''ll name the second database table NoteStyleTable since it provides the values related to the presentation style of our database data. It, too, has a primary key field of type AutoNumber that is uniquely generated by the database. The next field is the intStyleID, which we''''ll use to determine which note style to use. This use of a corresponding AutoNumber and Number field exemplifies the issue of primary key flexibility mentioned in the above paragraph.

I''''ve lined up the <TD> and <FONT> tags used in the VB code with the field names used in the NoteStyleID table. This is a fairly arbitrary process, and the names aren''''t limited to what an end developer could use for the values of these fields. For instance, an ASP developer could use the strTitleDateStart and strTextDataEnd fields to store the <TABLE><TR> and </TR></TABLE> tags that we are providing in the ASP file.

 
strTitleDataStart	<TD WIDTH="74" NOWRAP VALIGN="top">
strTitleFontStart	<FONT FACE="Verdana" SIZE="1" COLOR="GRAY">
			[TITLES CREATED BY VB CODE GO HERE]
strTitleFontEnd	</FONT>
strTitleDataEnd	</TD>

strTextDataStart	<TD WIDTH="124" VALIGN="top" BGCOLOR="#EFEFEF">
strTextFontStart 	<FONT FACE="Verdana" SIZE="1" COLOR="NAVY">
			[TITLE TEXT CREATED BY VB CODE GO HERE]
strTextFontEnd 	</FONT>
strTextDataEnd 	</TD>

I''''m always intrigued by how developers think of various ways to sneak other code into variables that I never considered at the time of development. Because of this, I try to provide as many presentation variables as reasonably possible when my VB method code constructs ready-to-render HTML return strings.

Given these needs for our HTML formatting, we''''ll design the NoteStyleTable with the fields listed below. Notice that the identification fields AutoStyleID and intStyleID have been separated, as explained in the discussion of the AutoNumber field above.

文章整理:西部数码--专业提供域名注册虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!