Datagrid 链接数据库Access

1@ Import Namespace="System" 
1@ Import Namespace="System.Data" 
1@ Import Namespace="System.Data.OleDb" 
 1<script language="c#" runat="server">   
 2void Page_Load()   
 3{   
 4string strConnection = "Provider=Microsoft.Jet.OleDb.4.0;";   
 5strConnection += @"Data Source=\\\genfs1\www11\etning\xml\Northwind.mdb";   
 6string strSQL = "SELECT * FROM Employees ";   
 7DataSet objDataSet = new DataSet();   
 8OleDbConnection objConnection = new OleDbConnection(strConnection);   
 9OleDbDataAdapter objAdapter = new OleDbDataAdapter(strSQL, objConnection);   
10objAdapter.Fill(objDataSet, "Employees");   
11DataView objDataView = new DataView(objDataSet.Tables["Employees"]);   
12dgNameList.DataSource=objDataView;   
13dgNameList.DataBind();   
14} 
15
16</script>
 1<html>
 2<body>
 3<h4>```
 4=Request.QueryString["id"]
 5```</h4>
 6<asp:datagrid allowcustompaging="false" autogeneratecolumns="false" backcolor="#ffffff" cellpadding="2" cellspacing="0" enableviewstate="false" font-name="?聬I" font-size="10pt" headerstyle-backcolor="#eeaadd" id="dgNameList" runat="server" showfooter="true">
 7<headerstyle backcolor="#00eeaa"></headerstyle>
 8<footerstyle backcolor="#aaaadd"></footerstyle>
 9<pagerstyle horizontalalign="Right" mode="NumericPages"></pagerstyle>
10<selecteditemstyle backcolor="blue"></selecteditemstyle>
11<itemstyle backcolor="#ffffee"></itemstyle>
12<alternatingitemstyle backcolor="#6699ff"></alternatingitemstyle>
13<columns>
14<asp:hyperlinkcolumn datanavigateurlfield="Title" datanavigateurlformatstring="datareadasp.aspx?id={0}" datatextfield="Title" datatextformatstring="{0:c}" headertext="Title"></asp:hyperlinkcolumn>
15</columns>
16</asp:datagrid>
17</body>
18</html>

点这里可以看到大多数的数据库链接!

Published At
Categories with Web编程
Tagged with
comments powered by Disqus