amespace =Namespace="System.Data.OleDb" %>
<script Language="VB" runat="server">
Sub Page_Load()Sub Page_Load(sender As Object, e As EventArgs)
Dim myConn As OleDbConnection
Dim myCmd As OleDbCommand
Dim myRd As OleDbDataReader
…中間略…
'' DataReader 物件連結「股票行情表」資料表
myRd = myCmd.ExecuteReader()
'' 呼叫副程式,利用 DataReader 物件逐欄逐列讀取資料表,然後填入輸出用的表格
OutputToTable( myRd )
'' 關閉資料庫連線
myConn.Close()
End Sub
Sub OutputToTable()Sub OutputToTable( Rd As OleDbDataReader )
Dim I As Integer
Dim row As TableRow
Dim cell As TableCell
'' 將資料表的「抬頭」填入表格中
row = New TableRow()
row.BackColor = Drawing.Color.Gold
For I = 0 To Rd.FieldCount - 1
cell = New TableCell()
cell.Text = Rd.GetName(I) '' 將 DataReader 所讀取的第 I 欄欄位抬頭設定給 TableCell
row.Cells.Add( cell ) '' 將 TableCell 加入 TableRow 之中
Next
Table2.Rows.Add( row )
'' 逐列讀出資料表,再將資料依序填入表格中
While Rd.Read()
row = New TableRow()
For I = 0 To Rd.FieldCount - 1
cell = New TableCell()
cell.Text = Rd.Item(I) '' 將 DataReader 所讀取的第 I 欄資料設定給 TableCell
row.Cells.Add( cell ) '' 將 TableCell 加入 TableRow 之中
If (I=0) Then
cell.BackColor=Drawing.Color.Goldenrod
cell.ForeColor=Drawing.Color.SteelBlue
End IF
If (I=Rd.FieldCount-4) And Val(cell.Text)>0 Then
cell.BackColor=Drawing.Color.Red
cell.ForeColor=Drawing.Color.Pink
ElseIf (I=Rd.FieldCount-4) And Val(cell.Text)<0 Then
cell.BackColor=Drawing.Color.LawnGreen
cell.ForeColor=Drawing.Color.GhostWhite
End If
If (I=Rd.FieldCount-3) And Val(cell.Text)>20 Then
cell.BackColor=Drawing.Color.Pink
cell.ForeColor=Drawing.Color.Red
End If
If (I=Rd.FieldCount-2) And Val(cell.Text)>17 Then
cell.BackColor=Drawing.Color.Pink
cell.ForeColor=Drawing.Color.Red
End If
If (I=Rd.FieldCount-1) And Val(cell.Text)>2000 Then
cell.BackColor=Drawing.Color.Red
cell.ForeColor=Drawing.Color.Pink
ElseIf (I=Rd.FieldCount-1) And Val(cell.Text)>200 Then
cell.BackC