Using System.Data; Using System.Data.OracleClient;
<%@ Import Namespace="System.Data"%> <%@ Import Namespace="System.Data.OracleClient"%> <%@ Page Language="C#" Debug="true" %> <script runat="server"> void Page_Load(object sender, EventArgs e) { BindData(); } void BindData() { //*** DataSet From DataSet ***// DataSet ds; ds = CreateDataSet(); int i; DataGrid dg; Label lbl; for(i = 0;i <= ds.Tables.Count - 1; i ++) { dg = new DataGrid(); dg.DataSource = ds.Tables.DefaultView; dg.AutoGenerateColumns = true; dg.DataBind(); lbl = new Label(); lbl.Text = "<br><b>" + ds.Tables[i].ToString() + "</b><br>"; this.lblText.Controls.Add(lbl); this.lblText.Controls.Add(dg); dg = null; } } //*** DataSet ***// protected DataSet CreateDataSet() { System.Data.OracleClient.OracleConnection objConn = new System.Data.OracleClient.OracleConnection(); System.Data.OracleClient.OracleCommand objCmd = new System.Data.OracleClient.OracleCommand(); System.Data.OracleClient.OracleDataAdapter dtAdapter = new System.Data.OracleClient.OracleDataAdapter(); DataSet ds = new DataSet(); int i; String strConnString,strSQL; strConnString = "Data Source=TCDB;User Id=myuser;Password=mypassword;"; String[] TablesName = new String[3]; TablesName[0] = "customer"; TablesName[1] = "audit_log"; TablesName[2] = "country"; for(i = 0; i<= TablesName.GetUpperBound(0) ; i ++) { strSQL = "SELECT * FROM " + TablesName[i] + " "; objConn.ConnectionString = strConnString; objCmd.Connection = objConn; objCmd.CommandText = strSQL; objCmd.CommandType = CommandType.Text; dtAdapter.SelectCommand = objCmd; dtAdapter.Fill(ds,TablesName[i]); } dtAdapter = null; objConn.Close(); objConn = null; return ds; //*** Return DataSet ***// } </script> <html> <head> <title>ThaiCreate.Com ASP.NET - System.Data.OracleClient</title> </head> <body> <form id="form1" runat="server"> <asp:Label id="lblText" runat="Server"></asp:Label> </form> </body> </html>
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท