Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,038

HOME > ASP.NET > ASP.NET System.Data.OleDb > ASP.NET System.Data.OleDb - DataTable() Part 2



Clound SSD Virtual Server

ASP.NET System.Data.OleDb - DataTable() Part 2

ASP.NET System.Data.OleDb - DataTable() การเขียน ASP.NET ใช้งาน NameSpace System.Data.OleDb กับ DataTable() ในการวนลูปข้อมูลเพื่อสร้างเป็นตารางด้วย Table,TableRow,TableCell

Instance NameSpace

VB.NET
1.Imports System.Data
2.Imports System.Data.OleDb


Language Code : VB.NET || C#

DataTable2.aspx

001.<%@ Import Namespace="System.Data"%>
002.<%@ Import Namespace="System.Data.OleDb"%>
003.<%@ Page Language="VB" %>
004.<script runat="server">
005. 
006.    Sub Page_Load(sender As Object, e As EventArgs)
007.        BindTable()
008.    End Sub
009. 
010.    '*** Bind To Table ***'
011.    Sub BindTable()
012. 
013.        '*** Test DataTable Structure ***'
014.        '********************************'
015.        Dim dt As DataTable
016.        Dim i As Integer
017. 
018. 
019.        dt = CreateDataTable()  
020. 
021.         
022.        '*** Create Table **'
023.        Dim Tb As New Table
024.        With Tb
025.            '.BorderColor = Drawing.Color.Black
026.            .BorderWidth = 1
027.        End With
028. 
029.        '*** Rows ***'
030.        Dim Tr As TableRow
031.        '*** Column ***'
032.        Dim Tc As TableCell
033.         
034. 
035.        '*** Create Header ***'
036. 
037.        '*** New Rows ***'
038.        Tr = New TableRow()
039. 
040.        '*** New Cell (Header CustomerID) ***'
041.        Tc = New TableCell()
042.        'Tc.BorderColor = Drawing.Color.Black
043.        Tc.BorderWidth = 1
044.        Dim lblHeadCustomerID As New Label
045.        With lblHeadCustomerID
046.            .Text = "CustomerID"
047.            .Font.Bold = True
048.        End With       
049.        Tc.Controls.Add(lblHeadCustomerID)  '*** Add lblHeadCustomerID To Cell ***'
050.        Tr.Cells.Add(Tc) '*** Add Cell To Rows ***'
051. 
052.        '*** New Cell (Header Name) ***'
053.        Tc = New TableCell()
054.        'Tc.BorderColor = Drawing.Color.Black
055.        Tc.BorderWidth = 1
056.        Dim lblHeadName As New Label
057.        With lblHeadName
058.            .Text = "Name"
059.            .Font.Bold = True
060.        End With       
061.        Tc.Controls.Add(lblHeadName)  '*** Add lblHeadName To Cell ***'
062.        Tr.Cells.Add(Tc) '*** Add Cell To Rows ***'
063. 
064.        '*** New Cell (Header Email) ***'
065.        Tc = New TableCell()
066.        'Tc.BorderColor = Drawing.Color.Black
067.        Tc.BorderWidth = 1
068.        Dim lblHeadEmail As New Label
069.        With lblHeadEmail
070.            .Text = "Email"
071.            .Font.Bold = True
072.        End With       
073.        Tc.Controls.Add(lblHeadEmail)  '*** Add lblHeadEmail To Cell ***'
074.        Tr.Cells.Add(Tc) '*** Add Cell To Rows ***'
075. 
076.        '*** New Cell (Header CountryCode) ***'
077.        Tc = New TableCell()
078.        'Tc.BorderColor = Drawing.Color.Black
079.        Tc.BorderWidth = 1
080.        Dim lblHeadCountryCode As New Label
081.        With lblHeadCountryCode
082.            .Text = "CountryCode"
083.            .Font.Bold = True
084.        End With       
085.        Tc.Controls.Add(lblHeadCountryCode)  '*** Add lblHeadCountryCode To Cell ***'
086.        Tr.Cells.Add(Tc) '*** Add Cell To Rows ***'
087. 
088.        '*** New Cell (Header Budget) ***'
089.        Tc = New TableCell()
090.        'Tc.BorderColor = Drawing.Color.Black
091.        Tc.BorderWidth = 1
092.        Dim lblHeadBudget As New Label
093.        With lblHeadBudget
094.            .Text = "Budget"
095.            .Font.Bold = True
096.        End With       
097.        Tc.Controls.Add(lblHeadBudget)  '*** Add lblHeadBudget To Cell ***'
098.        Tr.Cells.Add(Tc) '*** Add Cell To Rows ***'
099. 
100.        '*** New Cell (Header Used) ***'
101.        Tc = New TableCell()
102.        'Tc.BorderColor = Drawing.Color.Black
103.        Tc.BorderWidth = 1
104.        Dim lblHeadUsed As New Label
105.        With lblHeadUsed
106.            .Text = "Used"
107.            .Font.Bold = True
108.        End With       
109.        Tc.Controls.Add(lblHeadUsed)  '*** Add lblHeadUsed To Cell ***'
110.        Tr.Cells.Add(Tc) '*** Add Cell To Rows ***'
111. 
112.        Tb.Controls.Add(Tr)
113.        '*** End Header ***'
114.         
115.        '*************** Input DataTable To TableRows ***************'
116.            For  i = 0 To dt.Rows.Count - 1
117. 
118.                Tr = New TableRow()
119.                '*** New Cell (CustomerID) ***'
120.                Tc = New TableCell()
121.                'Tc.BorderColor = Drawing.Color.Black
122.                Tc.HorizontalAlign = HorizontalAlign.Center
123.                Tc.BorderWidth = 1
124.                Dim lblCustomerID As New Label
125.                With lblCustomerID
126.                    .Text = dt.Rows(i)("CustomerID")
127.                End With       
128.                Tc.Controls.Add(lblCustomerID)  '*** Add lblCustomerID To Cell ***'
129.                Tr.Cells.Add(Tc) '*** Add Cell To Rows ***'
130. 
131.                '*** New Cell (Name) ***'
132.                Tc = New TableCell()
133.                'Tc.BorderColor = Drawing.Color.Black
134.                Tc.BorderWidth = 1
135.                Dim lblName As New Label
136.                With lblName
137.                    .Text = dt.Rows(i)("Name")
138.                End With       
139.                Tc.Controls.Add(lblName)  '*** Add lblName To Cell ***'
140.                Tr.Cells.Add(Tc) '*** Add Cell To Rows ***'
141. 
142.                '*** New Cell (Email) ***'
143.                Tc = New TableCell()
144.                'Tc.BorderColor = Drawing.Color.Black
145.                Tc.BorderWidth = 1
146.                Dim lblEmail As New Label
147.                With lblEmail
148.                    .Text = dt.Rows(i)("Email")
149.                End With       
150.                Tc.Controls.Add(lblEmail)  '*** Add lblEmail To Cell ***'
151.                Tr.Cells.Add(Tc) '*** Add Cell To Rows ***'
152. 
153.                '*** New Cell (CountryCode) ***'
154.                Tc = New TableCell()
155.                'Tc.BorderColor = Drawing.Color.Black
156.                Tc.BorderWidth = 1
157.                Dim lblCountryCode As New Label
158.                With lblCountryCode
159.                    .Text = dt.Rows(i)("CountryCode")
160.                End With       
161.                Tc.Controls.Add(lblCountryCode)  '*** Add lblCountryCode To Cell ***'
162.                Tr.Cells.Add(Tc) '*** Add Cell To Rows ***'
163. 
164.                '*** New Cell (Budget) ***'
165.                Tc = New TableCell()
166.                'Tc.BorderColor = Drawing.Color.Black
167.                Tc.BorderWidth = 1
168.                Dim lblBudget As New Label
169.                With lblBudget
170.                    .Text = dt.Rows(i)("Budget")
171.                End With       
172.                Tc.Controls.Add(lblBudget)  '*** Add lblBudget To Cell ***'
173.                Tr.Cells.Add(Tc) '*** Add Cell To Rows ***'
174. 
175.                '*** New Cell (Used) ***'
176.                Tc = New TableCell()
177.                'Tc.BorderColor = Drawing.Color.Black
178.                Tc.BorderWidth = 1
179.                Dim lblUsed As New Label
180.                With lblUsed
181.                    .Text = dt.Rows(i)("Used")
182.                End With       
183.                Tc.Controls.Add(lblUsed)  '*** Add lblUsed To Cell ***'
184.                Tr.Cells.Add(Tc) '*** Add Cell To Rows ***'            
185.                Tb.Controls.Add(Tr)
186.            Next
187.        '************ End Input DataTable To TableRows *************'
188.         
189.        Me.lblTable.Controls.Add(Tb)
190.    End Sub
191. 
192.    '*** DataTable ***'
193.    Function CreateDataTable() As DataTable
194.        Dim objConn As New System.Data.OleDb.OleDbConnection
195.        Dim dtAdapter As System.Data.OleDb.OleDbDataAdapter
196.        Dim dt As New DataTable
197.        
198.        
199.        Dim strConnString As String
200.        strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="& _
201.        Server.MapPath("database/mydatabase.mdb")&";Jet OLEDB:Database Password=;"
202.        objConn = New System.Data.OleDb.OleDbConnection(strConnString)
203.        objConn.Open()
204. 
205.        Dim strSQL As String       
206.        strSQL = "SELECT * FROM customer"
207.         
208.        dtAdapter = New System.Data.OleDb.OleDbDataAdapter(strSQL, objConn)
209.        dtAdapter.Fill(dt)
210. 
211.        Return dt '*** Return DataTable ***'
212. 
213.        dtAdapter = Nothing
214. 
215.        objConn.Close()
216.        objConn = Nothing
217.    End Function
218. 
219.</script>
220.<html>
221.<head>
222.<title>ThaiCreate.Com ASP.NET - System.Data.OleDb</title>
223.</head>
224.<body>
225.    <form id="form1" runat="server">
226.    <asp:Label id="lblTable" runat="server"></asp:Label>
227.    </form>
228.</body>
229.</html>


Screenshot

ASP.NET System.Data.OleDb



ASP.NET - DataTable

ASP.NET - DataSet






   
Hate it
Don't like it
It's ok
Like it
Love it
Share

Property & Method (Others Related)

ASP.NET System.Data.OleDb - DataTable()

ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท


ลองใช้ค้นหาข้อมูล


   


Bookmark.   
       
  By : ThaiCreate.Com Team (บทความเป็นลิขสิทธิ์ของเว็บไทยครีเอทห้ามนำเผยแพร่ ณ เว็บไซต์อื่น ๆ)
  Score Rating :  
  Create/Update Date : 2008-12-01 11:47:36 / 2009-07-07 09:08:07
  Download : Download  ASP.NET System.Data.OleDb - DataTable() Part 2
 Sponsored Links / Related

 
ASP.NET System.Data.OleDb - Connection String
Rating :

 
ASP.NET System.Data.OleDb - DataReader()
Rating :

 
ASP.NET System.Data.OleDb - DataAdapter()
Rating :

 
ASP.NET System.Data.OleDb - DataTable()
Rating :

 
ASP.NET System.Data.OleDb - DataSet()
Rating :

 
ASP.NET System.Data.OleDb - ExecuteReader()
Rating :

 
ASP.NET System.Data.OleDb - ExecuteNonQuery()
Rating :

 
ASP.NET System.Data.OleDb - ExecuteScalar()
Rating :

 
ASP.NET System.Data.OleDb - Transaction()
Rating :

 
ASP.NET System.Data.OleDb - Parameter Query (OleDbParameter)
Rating :


ThaiCreate.Com Forum


Comunity Forum Free Web Script
Jobs Freelance Free Uploads
Free Web Hosting Free Tools

สอน PHP ผ่าน Youtube ฟรี
สอน Android การเขียนโปรแกรม Android
สอน Windows Phone การเขียนโปรแกรม Windows Phone 7 และ 8
สอน iOS การเขียนโปรแกรม iPhone, iPad
สอน Java การเขียนโปรแกรม ภาษา Java
สอน Java GUI การเขียนโปรแกรม ภาษา Java GUI
สอน JSP การเขียนโปรแกรม ภาษา Java
สอน jQuery การเขียนโปรแกรม ภาษา jQuery
สอน .Net การเขียนโปรแกรม ภาษา .Net
Free Tutorial
สอน Google Maps Api
สอน Windows Service
สอน Entity Framework
สอน Android
สอน Java เขียน Java
Java GUI Swing
สอน JSP (Web App)
iOS (iPhone,iPad)
Windows Phone
Windows Azure
Windows Store
Laravel Framework
Yii PHP Framework
สอน jQuery
สอน jQuery กับ Ajax
สอน PHP OOP (Vdo)
Ajax Tutorials
SQL Tutorials
สอน SQL (Part 2)
JavaScript Tutorial
Javascript Tips
VBScript Tutorial
VBScript Validation
Microsoft Access
MySQL Tutorials
-- Stored Procedure
MariaDB Database
SQL Server Tutorial
SQL Server 2005
SQL Server 2008
SQL Server 2012
-- Stored Procedure
Oracle Database
-- Stored Procedure
SVN (Subversion)
แนวทางการทำ SEO
ปรับแต่งเว็บให้โหลดเร็ว


Hit Link
   







Load balance : Server 05
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2025 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่