Sub showpage()
connectdb()
Requestidpageshow()
Dim StrSQL As String = "Select * From Page WHERE PageId =" & idpageshow & ""
Dim myda As New OleDbDataAdapter(StrSQL, objConn)
Dim ds As New DataSet()
Dim PageId, PageSet As Integer
Dim PagePhoto, PageName, PageIntro, PageDetail As String
myda.Fill(ds, "showprofiles")
PageId = ds.Tables("showprofiles").Rows(0).Item(0) '*** colume PageId ***'
PageName = ds.Tables("showprofiles").Rows(0).Item(1) '*** colume PageName ***'
PageIntro = ds.Tables("showprofiles").Rows(0).Item(2) '*** colume PageIntro ***'
PageDetail = ds.Tables("showprofiles").Rows(0).Item(3) '*** colume PageDetail ***'
PagePhoto = ds.Tables("showprofiles").Rows(0).Item(4) '*** colume PagePhoto ***'
PageSet = ds.Tables("showprofiles").Rows(0).Item(5) '*** colume PageSet ***'
lblmenu.Text = PageName
lblintro.Text = PageIntro
lbldetail.text = PageDetail
'ถ้าเกิดไม่เจอให้แสดงรูปพื้นฐานแทน
If PagePhoto = "" Then
imgprofile.ImageUrl = "images/Page/" & "Page.jpg"
imgprofile.Height = 400
imgprofile.Width = 500
imgprofile.BorderWidth = 1
Else
'ถ้าเจอให้ใช้รูปในdb
imgprofile.ImageUrl = "images/Page/" & PagePhoto
imgprofile.Height = 400
imgprofile.Width = 500
imgprofile.BorderWidth = 1
End If
End Sub
Date :
2011-02-11 09:09:47
By :
IrisCode
No. 3
Guest
Code (VB.NET)
Sub BindControl()
connectdb()
Dim dt As New DataTable
Dim strSQL As String
strSQL = "SELECT * FROM SubPage WHERE PageId =" & idpageshow & ""
Dim dtReader As OleDbDataReader
objCmd = New OleDbCommand(strSQL, objConn)
dtReader = objCmd.ExecuteReader()
'*** BindData to Repeater ***'
myRepeater.DataSource = dtReader
myRepeater.DataBind()
dtReader.Close()
dtReader = Nothing
End Sub
<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Data.OleDb"%>
<%@ Page Language="VB" %>
<script runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
BindTable()
End Sub
'*** Bind To Table ***'
Sub BindTable()
'*** Test DataTable Structure ***'
'********************************'
Dim dt As DataTable
Dim i As Integer
dt = CreateDataTable()
'*** Create Table **'
Dim Tb As New Table
With Tb
'.BorderColor = Drawing.Color.Black
.BorderWidth = 1
End With
'*** Rows ***'
Dim Tr As TableRow
'*** Column ***'
Dim Tc As TableCell
'*** Create Header ***'
'*** New Rows ***'
Tr = New TableRow()
'*** New Cell (Header CustomerID) ***'
Tc = New TableCell()
'Tc.BorderColor = Drawing.Color.Black
Tc.BorderWidth = 1
Dim lblHeadCustomerID As New Label
With lblHeadCustomerID
.Text = "CustomerID"
.Font.Bold = True
End With
Tc.Controls.Add(lblHeadCustomerID) '*** Add lblHeadCustomerID To Cell ***'
Tr.Cells.Add(Tc) '*** Add Cell To Rows ***'
'*** New Cell (Header Name) ***'
Tc = New TableCell()
'Tc.BorderColor = Drawing.Color.Black
Tc.BorderWidth = 1
Dim lblHeadName As New Label
With lblHeadName
.Text = "Name"
.Font.Bold = True
End With
Tc.Controls.Add(lblHeadName) '*** Add lblHeadName To Cell ***'
Tr.Cells.Add(Tc) '*** Add Cell To Rows ***'
'*** New Cell (Header Email) ***'
Tc = New TableCell()
'Tc.BorderColor = Drawing.Color.Black
Tc.BorderWidth = 1
Dim lblHeadEmail As New Label
With lblHeadEmail
.Text = "Email"
.Font.Bold = True
End With
Tc.Controls.Add(lblHeadEmail) '*** Add lblHeadEmail To Cell ***'
Tr.Cells.Add(Tc) '*** Add Cell To Rows ***'
'*** New Cell (Header CountryCode) ***'
Tc = New TableCell()
'Tc.BorderColor = Drawing.Color.Black
Tc.BorderWidth = 1
Dim lblHeadCountryCode As New Label
With lblHeadCountryCode
.Text = "CountryCode"
.Font.Bold = True
End With
Tc.Controls.Add(lblHeadCountryCode) '*** Add lblHeadCountryCode To Cell ***'
Tr.Cells.Add(Tc) '*** Add Cell To Rows ***'
'*** New Cell (Header Budget) ***'
Tc = New TableCell()
'Tc.BorderColor = Drawing.Color.Black
Tc.BorderWidth = 1
Dim lblHeadBudget As New Label
With lblHeadBudget
.Text = "Budget"
.Font.Bold = True
End With
Tc.Controls.Add(lblHeadBudget) '*** Add lblHeadBudget To Cell ***'
Tr.Cells.Add(Tc) '*** Add Cell To Rows ***'
'*** New Cell (Header Used) ***'
Tc = New TableCell()
'Tc.BorderColor = Drawing.Color.Black
Tc.BorderWidth = 1
Dim lblHeadUsed As New Label
With lblHeadUsed
.Text = "Used"
.Font.Bold = True
End With
Tc.Controls.Add(lblHeadUsed) '*** Add lblHeadUsed To Cell ***'
Tr.Cells.Add(Tc) '*** Add Cell To Rows ***'
Tb.Controls.Add(Tr)
'*** End Header ***'
'*************** Input DataTable To TableRows ***************'
For i = 0 To dt.Rows.Count - 1
Tr = New TableRow()
'*** New Cell (CustomerID) ***'
Tc = New TableCell()
'Tc.BorderColor = Drawing.Color.Black
Tc.HorizontalAlign = HorizontalAlign.Center
Tc.BorderWidth = 1
Dim lblCustomerID As New Label
With lblCustomerID
.Text = dt.Rows(i)("CustomerID")
End With
Tc.Controls.Add(lblCustomerID) '*** Add lblCustomerID To Cell ***'
Tr.Cells.Add(Tc) '*** Add Cell To Rows ***'
'*** New Cell (Name) ***'
Tc = New TableCell()
'Tc.BorderColor = Drawing.Color.Black
Tc.BorderWidth = 1
Dim lblName As New Label
With lblName
.Text = dt.Rows(i)("Name")
End With
Tc.Controls.Add(lblName) '*** Add lblName To Cell ***'
Tr.Cells.Add(Tc) '*** Add Cell To Rows ***'
'*** New Cell (Email) ***'
Tc = New TableCell()
'Tc.BorderColor = Drawing.Color.Black
Tc.BorderWidth = 1
Dim lblEmail As New Label
With lblEmail
.Text = dt.Rows(i)("Email")
End With
Tc.Controls.Add(lblEmail) '*** Add lblEmail To Cell ***'
Tr.Cells.Add(Tc) '*** Add Cell To Rows ***'
'*** New Cell (CountryCode) ***'
Tc = New TableCell()
'Tc.BorderColor = Drawing.Color.Black
Tc.BorderWidth = 1
Dim lblCountryCode As New Label
With lblCountryCode
.Text = dt.Rows(i)("CountryCode")
End With
Tc.Controls.Add(lblCountryCode) '*** Add lblCountryCode To Cell ***'
Tr.Cells.Add(Tc) '*** Add Cell To Rows ***'
'*** New Cell (Budget) ***'
Tc = New TableCell()
'Tc.BorderColor = Drawing.Color.Black
Tc.BorderWidth = 1
Dim lblBudget As New Label
With lblBudget
.Text = dt.Rows(i)("Budget")
End With
Tc.Controls.Add(lblBudget) '*** Add lblBudget To Cell ***'
Tr.Cells.Add(Tc) '*** Add Cell To Rows ***'
'*** New Cell (Used) ***'
Tc = New TableCell()
'Tc.BorderColor = Drawing.Color.Black
Tc.BorderWidth = 1
Dim lblUsed As New Label
With lblUsed
.Text = dt.Rows(i)("Used")
End With
Tc.Controls.Add(lblUsed) '*** Add lblUsed To Cell ***'
Tr.Cells.Add(Tc) '*** Add Cell To Rows ***'
Tb.Controls.Add(Tr)
Next
'************ End Input DataTable To TableRows *************'
Me.lblTable.Controls.Add(Tb)
End Sub
'*** DataTable ***'
Function CreateDataTable() As DataTable
Dim objConn As New System.Data.OleDb.OleDbConnection
Dim dtAdapter As System.Data.OleDb.OleDbDataAdapter
Dim dt As New DataTable
Dim strConnString As String
strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="& _
Server.MapPath("database/mydatabase.mdb")&";Jet OLEDB:Database Password=;"
objConn = New System.Data.OleDb.OleDbConnection(strConnString)
objConn.Open()
Dim strSQL As String
strSQL = "SELECT * FROM customer"
dtAdapter = New System.Data.OleDb.OleDbDataAdapter(strSQL, objConn)
dtAdapter.Fill(dt)
Return dt '*** Return DataTable ***'
dtAdapter = Nothing
objConn.Close()
objConn = Nothing
End Function
</script>
<html>
<head>
<title>ThaiCreate.Com ASP.NET - System.Data.OleDb</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Label id="lblTable" runat="server"></asp:Label>
</form>
</body>
</html>