1 / 10

第八章

存取. 顯示表格. DataGrid. DataTable. 第八章. DataGrid 與 DataTable. 瀏覽器. 暑資碩三 房玄博 報告. 股票代號. 股票名稱. 收盤價. 漲跌. 最高價. 最低價. 成交量. 8-1 DataTable 的資料結構. 0001. 鴻運. 18.6. -0.3. 18.8. 18.6. 3552. 0003. 成長. 24.9. -0.1. 25. 24.9. 179. 0004. 國民. 21.3. -0.4. 21.5. 21.1. 1740. 0005.

Download Presentation

第八章

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 存取 顯示表格 DataGrid DataTable 第八章 DataGrid 與 DataTable 瀏覽器 暑資碩三 房玄博 報告

  2. 股票代號 股票名稱 收盤價 漲跌 最高價 最低價 成交量 8-1 DataTable 的資料結構 0001 鴻運 18.6 -0.3 18.8 18.6 3552 0003 成長 24.9 -0.1 25 24.9 179 0004 國民 21.3 -0.4 21.5 21.1 1740 0005 成功 17.2 -0.4 17.5 17.2 177 0006 鴻福 17.5 -0.3 17.6 17.5 100 標題欄(抬頭) Data row Data column

  3. 8-1 DataTable 的建構 • 開啓資料庫 Dim Table As System.Data.Datatable Table = OpenMdbTable(“Sample.mdb”,”股 票行情表“)

  4. 8-1 DataTable 的建構 開啓資料庫 完整範例 <!- - #include File=“Mdb.vb” - - > <Html> <Body BgColor="White"><Center> <H3>Grid01.aspx -- 用 DataGrid 顯示 DataTable 的資料<HR></H3> <asp:DataGrid runat="server" id="MyGrid" /> <p> <HR></Center></Body> </Html> <script Language="VB" runat="server"> Sub Page_Load(sender As Object, e As EventArgs) Dim Table As System.Data.DataTable Table = OpenMdbTable( "Sample.mdb", "股票行情表" ) ' DataGrid 與 DataTable 的資料繫結 MyGrid.DataSource = Table.DefaultView MyGrid.DataBind() End Sub </script>

  5. 8-1 DataTable 的建構 三個步驟 1.建立Data Table物件 Dim Table As New Datatable 2建立欄位 3.加 入資料列 寫入資料庫

  6. 8-1 DataTable 的建構 完整範例 Dim 姓名() = { "陳桶一", "黃光權", "胡生妙", "王為全", _ "李日正", "劉德菖", "方正一" } Dim 國文() = { 90, 58, 41, 95, 59, 28, 98 } Dim 英文() = { 76, 77, 14, 97, 66, 11, 100} Dim 數學() = { 98, 75, 33, 87, 57, 33, 100} Sub Page_Load(sender As Object, e As EventArgs) Dim I As Integer

  7. 8-1 DataTable 的建構 ' Part 1: 宣告並且建立 DataTable 物件 Dim Table As New DataTable ' Part 2: 建立欄位 Table.Columns.Add(New DataColumn("姓名", GetType(String))) Table.Columns.Add(New DataColumn("國文", GetType(Integer))) Table.Columns.Add(New DataColumn("英文", GetType(Integer))) Table.Columns.Add(New DataColumn("數學", GetType(Integer))) ' Part 3: 加入資料列 For I = 0 To UBound(姓名) Dim Row As DataRow Row = Table.NewRow() Row("姓名") = 姓名(I) Row("國文") = 國文(I) Row("英文") = 英文(I) Row("數學") = 數學(I) Table.Rows.Add(Row) Next Msg.Text = "逐欄逐列填入資料 DataTable 完成!"

  8. 8-2 DataGrid • DataGrid的安插與資料繫結 1.安插標示 <asp:DataGrid runat="server" id=“ID" /> 或 <asp:DataGrid runat="server" id=“ID"> </asp:DataGrid> 2.DataGrid 與 DataTable繫結 DataGrid.DataSource=DataTable.DefaultView DataGrid.DataBind()

  9. 8-2 DataGrid 完整範例 <%@ Import Namespace="System.Data" %> <!-- #include File="Mdb.vb" --> <Html> <Body BgColor="White"><Center> <H3>Grid01.aspx -- 用 DataGrid 顯示 DataTable 的資料<HR></H3> <asp:DataGrid runat="server" id="MyGrid" /> <p> <HR></Center></Body> </Html> <script Language="VB" runat="server"> Sub Page_Load(sender As Object, e As EventArgs) Dim Table As DataTable Table = OpenMdbTable( “Sample.mdb”, “股票行情表” ) (可改成成績單) ' DataGrid 與 DataTable 的資料繫結 MyGrid.DataSource = Table.DefaultView MyGrid.DataBind() End Sub</script>

  10. 第八章 報告完畢 謝謝聆聽

More Related