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 Oracle (System.Data.OracleClient) > ASP.NET Oracle Random Record


ASP.NET Oracle Random Record

ASP.NET Oracle Random Record ตัวอย่างการเขียน ASP.NET กับ Oracle สุ่มข้อมูล (Random) จากฐานข้อมูล

Instance NameSpace

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


ASP.NET & System.Data.OracleClient

Language Code : VB.NET || C#

AspNetOracleRandomRecord.aspx

001.<%@ Import Namespace="System.Data"%>
002.<%@ Import Namespace="System.Data.OracleClient"%>
003.<%@ Page Language="VB" %>
004.<script runat="server">
005. 
006.    Dim objConn As OracleConnection
007.    Dim objCmd As OracleCommand
008. 
009.    Sub Page_Load(sender As Object, e As EventArgs)
010.        Dim strConnString As String
011.        strConnString = "Data Source=TCDB;User Id=myuser;Password=mypassword;"
012.        objConn = New OracleConnection(strConnString)
013.        objConn.Open()
014. 
015.        BindData()
016.    End Sub
017. 
018.    Sub BindData()
019.        Dim strSQL As String
020.        strSQL = "SELECT * FROM ( SELECT * FROM customer ORDER BY dbms_random.value ) WHERE rownum <= 3"
021. 
022.        Dim dtReader As OracleDataReader
023.        objCmd = New OracleCommand(strSQL, objConn)
024.        dtReader = objCmd.ExecuteReader()
025.         
026.        '*** BindData to Repeater ***'
027.        myRepeater.DataSource = dtReader
028.        myRepeater.DataBind()
029. 
030.        dtReader.Close()
031.        dtReader = Nothing
032. 
033.    End Sub
034. 
035.    Sub Page_UnLoad()
036.        objConn.Close()
037.        objConn = Nothing
038.    End Sub
039. 
040.    Sub myRepeater_ItemDataBound(ByVal sender As Object, ByVal e As RepeaterItemEventArgs) Handles myRepeater.ItemDataBound
041. 
042.            '*** CustomerID ***'
043.            Dim lblCustomerID As Label = CType(e.Item.FindControl("lblCustomerID"),Label)
044.            IF Not IsNothing(lblCustomerID) Then
045.                lblCustomerID.Text = e.Item.DataItem("CustomerID")
046.            End IF
047. 
048.            '*** Name ***'
049.            Dim lblName As Label = CType(e.Item.FindControl("lblName"),Label)
050.            IF Not IsNothing(lblName) Then
051.                lblName.Text = e.Item.DataItem("Name")
052.            End IF
053. 
054.            '*** Email ***'
055.            Dim lblEmail As Label = CType(e.Item.FindControl("lblEmail"),Label)
056.            IF Not IsNothing(lblEmail) Then
057.                lblEmail.Text = e.Item.DataItem("Email")
058.            End IF
059. 
060.            '*** CountryCode ***'
061.            Dim lblCountryCode As Label = CType(e.Item.FindControl("lblCountryCode"),Label)
062.            IF Not IsNothing(lblCountryCode) Then
063.                lblCountryCode.Text = e.Item.DataItem("CountryCode")
064.            End IF
065. 
066.            '*** Budget ***'
067.            Dim lblBudget As Label = CType(e.Item.FindControl("lblBudget"),Label)
068.            IF Not IsNothing(lblBudget) Then
069.                lblBudget.Text = e.Item.DataItem("Budget")
070.            End IF
071. 
072.            '*** Used ***'
073.            Dim lblUsed As Label = CType(e.Item.FindControl("lblUsed"),Label)
074.            IF Not IsNothing(lblUsed) Then
075.                lblUsed.Text = e.Item.DataItem("Used")
076.            End IF
077.    End Sub
078. 
079.</script>
080.<html>
081.<head>
082.<title>ThaiCreate.Com ASP.NET - Oracle</title>
083.</head>
084.<body>
085.    <form id="form1" runat="server">
086.    <asp:Repeater id="myRepeater" runat="server">
087.    <HeaderTemplate>
088.        <table border="1">
089.            <tr>
090.                <th>CustomerID</th>
091.                <th>Name</th>
092.                <th>Email</th>
093.                <th>CountryCode</th>
094.                <th>Budget</th>
095.                <th>Used</th>
096.            </tr>
097.    </HeaderTemplate>
098.    <ItemTemplate>
099.        <tr>
100.            <td align="center"><asp:Label id="lblCustomerID" runat="server"></asp:Label></td>
101.            <td><asp:Label id="lblName" runat="server"></asp:Label></td>
102.            <td><asp:Label id="lblEmail" runat="server"></asp:Label></td>
103.            <td align="center"><asp:Label id="lblCountryCode" runat="server"></asp:Label></td>
104.            <td align="right"><asp:Label id="lblBudget" runat="server"></asp:Label></td>
105.            <td align="right"><asp:Label id="lblUsed" runat="server"></asp:Label></td>
106.        </tr>        
107.    </ItemTemplate>
108.    </asp:Repeater>
109.    </form>
110.</body>
111.</html>




Screenshot

ASP.NET & Oracle

Note!! โปรดทราบ เนื่องจาก System.Data.OracleClient ได้ถูก Obsolete ไปแล้ว ฉะนั้นจึงจะต้องใช้ Oracle.DataAccess แทน โดยสามารถประกาศเรียกได้จาก



จากนั้นให้ใช้ using หรือ Import คอนเน็คเตอร์ใหม่คือ Oracle.DataAccess ส่วนคำสั่งอื่น ๆ ยังคงเหมือนเดิม


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


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


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


   


Bookmark.   
       
  By : ThaiCreate.Com Team (บทความเป็นลิขสิทธิ์ของเว็บไทยครีเอทห้ามนำเผยแพร่ ณ เว็บไซต์อื่น ๆ)
  Score Rating :  
  Create/Update Date : 2008-10-26 23:06:22 / 2017-03-29 10:47:03
  Download : Download  ASP.NET Oracle Random Record
 Sponsored Links / Related

 
ASP.NET Oracle Connect to Database
Rating :

 
ASP.NET Oracle List Table Properties
Rating :

 
ASP.NET Oracle List Record
Rating :

 
ASP.NET Oracle & OleDb (System.Data.OleDb)
Rating :

 
ASP.NET Oracle & Odbc (System.Data.Odbc)
Rating :

 
ASP.NET Oracle List Record Paging/Pagination
Rating :

 
ASP.NET Oracle Search Record
Rating :

 
ASP.NET Oracle Search Record Paging/Pagination
Rating :

 
ASP.NET Oracle Add/Insert Record
Rating :

 
ASP.NET Oracle Add-Insert Multiple Record
Rating :

 
ASP.NET Oracle Check Already Exists Add/Insert Record
Rating :

 
ASP.NET Oracle Transaction (BeginTransaction,Commit,Rollback)
Rating :

 
ASP.NET Oracle Edit/Update Record
Rating :

 
ASP.NET Oracle Delete Record
Rating :

 
ASP.NET Oracle Multiple Checkbox Delete Record
Rating :

 
ASP.NET Oracle and GridView, DataSource
Rating :

 
ASP.NET Oracle Database Class
Rating :

 
ASP.NET Oracle Database Class (Visual Studio .Net 2003 - .NET 1.1)
Rating :

 
ASP.NET Oracle Database Class (Visual Studio 2005,2008,2010 - .NET 2.0,3.5,4.0)
Rating :

 
ASP.NET Oracle BLOB Binary Data and Parameterized Query
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
   





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 อัตราราคา คลิกที่นี่