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 ***// DataSet ds; ds = CreateDataSet(); //*** Adding Rows to DataSet ***// DataRow dr; dr = ds.Tables["customer"].NewRow(); dr["CustomerID"] = "C005"; dr["Name"] = "Weerachai Nukitram"; dr["Email"] = "[email protected]"; dr["CountryCode"] = "TH"; dr["Budget"] = "2000000"; dr["Used"] = "100000"; ds.Tables["customer"].NewRow(); ds.Tables["customer"].Rows.Add(dr); //*** Adding Rows to DataSet ***// this.myDataGrid.DataSource = ds.Tables[0].DefaultView; this.myDataGrid.DataBind(); } //*** 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(); String strConnString,strSQL; strConnString = "Data Source=TCDB;User Id=myuser;Password=mypassword;"; strSQL = "SELECT * FROM customer "; objConn.ConnectionString = strConnString; objCmd.Connection = objConn; objCmd.CommandText = strSQL; objCmd.CommandType = CommandType.Text; dtAdapter.SelectCommand = objCmd; dtAdapter.Fill(ds,"customer"); 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:DataGrid id="myDataGrid" AutoGenerateColumns="true" runat="Server"></asp:DataGrid> </form> </body> </html>
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท