<%@ Import Namespace="System.Data"%> <%@ Import Namespace="System.Data.OleDb"%> <%@ Page Language="C#" Debug="true" %> <script runat="server"> OleDbConnection objConn; OleDbCommand objCmd; String strCusID = "C001"; //*** Request.QueryString["CusID"] ***// void Page_Load(object sender,EventArgs e) { String strConnString; strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("database/mydatabase.mdb")+";"; objConn = new OleDbConnection(strConnString); objConn.Open(); BindData(); } void BindData() { String strSQL; strSQL = "SELECT * FROM customer WHERE CustomerID = '" + strCusID +"' "; OleDbDataReader dtReader; objCmd = new OleDbCommand(strSQL, objConn); dtReader = objCmd.ExecuteReader(); //*** BindData to DetailsView ***// myDetailsView.DataSource = dtReader; myDetailsView.DataBind(); dtReader.Close(); dtReader = null; } void Page_UnLoad() { objConn.Close(); objConn = null; } </script> <html> <head> <title>ThaiCreate.Com ASP.NET - DetailsView</title> </head> <body> <form id="form1" runat="server"> <asp:DetailsView id="myDetailsView" runat="server" BackColor="LightGoldenrodYellow" BorderColor="Tan" BorderWidth="1px" CellPadding="2" ForeColor="Black" GridLines="None"> <FooterStyle BackColor="Tan" /> <PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" HorizontalAlign="Center" /> <HeaderStyle BackColor="Tan" Font-Bold="True" /> <EditRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" /> <AlternatingRowStyle BackColor="PaleGoldenrod" /> </asp:DetailsView> </form> </body> </html>
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท