The records returned from the NoteTitle table of our example database, via the SQL statement used here, hold the following values: The vRecordArray holds a zero-based array with the first array dimension corresponding to the database fields, which are the NoteID and NoteTitle fields in our example code. NoteID will have an index of "0", since it was the first field to be returned in the SQL statement, and NoteTitle will have an index of "1". The second dimension of the array will index the number and order of the NoteID and NoteTitle record fields values that were returned, starting with "0". This all sounds more complex than it is. Here are the corresponding array indexes that match the database field values of the tables displayed above.
SELECT NoteID, NoteTitle FROM NoteTable
NoteID NoteTitle
1 Intro
2 Style Tables
3 GetRows()
4 Buffering
5 Transactions
Since the ones and zeros can be confusing, we can replace them with the constants that were declared at the start of our code. This makes the code more readable, albeit more verbose.
sql = "SELECT NoteID, NoteTitle FROM NoteTable"
NoteID NoteTitle
-------------------------------------------------------------------------
vRecordArray(0, 0) = 1 vRecordArray(1, 0) = "Intro"
vRecordArray(0, 1) = 2 vRecordArray(1, 1) = "Style Tables"
vRecordArray(0, 2) = 3 vRecordArray(1, 2) = "GetRows()"
vRecordArray(0, 3) = 4 vRecordArray(1, 3) = "Buffering"
vRecordArray(0, 4) = 5 vRecordArray(1, 4) = "Transactions "
Const ARRAY_NOTE_ID_INDEX = 0
Const ARRAY_TITLE_INDEX = 1
NoteID NoteTitle
-------------------------------------------------------------------------
vRecordArray(ARRAY_NOTE_ID_INDEX, 0) = 1 vRecordArray(ARRAY_TITLE_INDEX, 0) = "Intro"
vRecordArray(ARRAY_NOTE_ID_INDEX, 1) = 2 vRecordArray(ARRAY_TITLE_INDEX, 1) = "Style Tables"
vRecordArray(ARRAY_NOTE_ID_INDEX, 2) = 3 vRecordArray(ARRAY_TITLE_INDEX, 2) = "GetRows()"
vRecordArray(ARRAY_NOTE_ID_INDEX, 3) = 4 vRecordArray(ARRAY_TITLE_INDEX, 3) = "Buffering"
vRecordArray(ARRAY_NOTE_ID_INDEX, 4) = 5 vRecordArray(ARRAY_TITLE_INDEX, 4) = "Transactions "
Since all our database information is tightly stored away in our vRecordArray variable, we''''ll close up our database connection and loop through the array to send back some example demonstration code as a first test of our GetRows() array.
The first thing to do is store the value of the last index of our array in the lngArrayCount variable. This gives us a numerical value of were the array ends (see the code below). Remember, this array is zero based, so the value of lngArrayCount will really be one minus the actual number of items within the array. Next, we''''ll loop through our array while storing the string concatenations in the strReturnString variable.
''''///// Get the number of titles stored in the array
lngArrayCount = UBound(vRecordArray, 2)
The code above will construct a single string, held in strReturnString, with the value displayed below.
''''///// Loop through array
For lngIndexCount = 0 To lngArrayCount
''''///// Get data from the array populated by the GetRows() method
strReturnString = strReturnString & "NoteID = "
strReturnString = strReturnString & vRecordArray(ARRAY_NOTE_ID_INDEX, lngIndexCount)
strReturnString = strReturnString & " NoteText = "
strReturnString = strReturnString & vRecordArray(ARRAY_TITLE_INDEX, lngIndexCount)
strReturnString = strReturnString & "<BR>" & vbCrLf
Next
This VB constant vbCrLf that is assigned to the last line of the code within the loop, and directly after the <BR> string value, will produce a Carriage Return/LineFeed that places a line break at the end of each record line of text for easy HTML source-code reading.
NoteID = 1 NoteText = Intro<BR>
NoteID = 2 NoteText = Style Tables<BR>
NoteID = 3 NoteText = GetRows()<BR>
NoteID = 4 NoteText = Buffering<BR>
NoteID = 5 NoteText = Transactions<BR>
文章整理:西部数码--专业提供域名注册、虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!




