c12-04.aspx

来自「一本很好的教材.C#开发者必备.内容全面,很难得哦.」· ASPX 代码 · 共 46 行

ASPX
46
字号
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>

<Html>
<Body BgColor="White">
<asp:DataGrid 
     AllowPage="True"
     PageSize="10"
     HeaderStyle-BackColor="Blue" 
     AlternatingItemStyle--BackColor="Blue"
     BorderColor="Red"
     PageStyle-HorizontalAlign="Left"     
     id="Grid1" runat="server"/>
   <script language="c#" runat="server">
void Page_Load(Object sender, EventArgs E)
   {
     DataSet ds = new DataSet() ;
 String ConnStr = "Provider=SQLOLEDB.1;Password=pass;Persist Security Info=True;User ID=sa;Initial Catalog=pubs;DataSource=localhost" ;
     OleDbConnection Conn = new OleDbConnection(ConnStr) ;
     Conn.Open() ;           
  //  运行第一个 SQL 指令,产生第一个 DataTable 
     String SQL = "Select * from authors" ;
     OleDbCommand Cmd = new OleDbCommand( SQL, Conn ) ;
     OleDbDataAdapter Adapter = new OleDbDataAdapter ( ) ;
     Adapter.SelectCommand = Cmd ;
     Adapter.Fill(ds, "authors") ;
 //  运行第二个 SQL 指令,产生第二个 DataTable
     SQL = "Select * from jobs" ;
     Cmd = new OleDbCommand( SQL, Conn ) ;
     Adapter.SelectCommand = Cmd ;
     Adapter.Fill(ds, "jobs") ;
     
     //  运行第三个 SQL 指令,产生第三个 DataTable 
     SQL = "Select * from employee" ;
     Cmd = new OleDbCommand( SQL, Conn ) ;
     Adapter.SelectCommand = Cmd ;
     Adapter.Fill(ds, "employee") ;

     Grid1.DataSource=ds.Tables["authors"].DefaultView ;
     Grid1.DataBind() ;
   }
   </script>   

</Blockquote><Hr>
</Body>
</Html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?