Web.config配置
appSettings中配置access与sqlserver
<appSettings>
<add key="OleDbConnectionString" value="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="/>
<add key="AccessDbPath" value="App_Data/chinabase.mdb;"/>
<add key="NorthwindConnectionString" value="DataSource=.;database=Northwind;uid=sa;pwd=123"/>
<add key="ChinabaseSQLServerConnectionString" value="Data Source=808644DA83B446C/SQLEXPRESS;Initial Catalog=ChinabaseSQLServer;Persist Security Info=True;User ID=sa;Password=123"/>
</appSettings>
前台页面:
<asp:GridView ID="GridView1" AutoGenerateColumns="false" OnRowEditing="GridView1_RowEditing"
OnRowUpdating="GridView1_RowUpdating" OnRowCancelingEdit="GridView1_RowCancelingEdit"
EmptyDataText="No records found" CellPadding="0" CellSpacing="0"
Font-Size="11pt" HeaderStyle-Font-Size="12pt" EditRowStyle-Font-Size="11pt"
BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px"
OnRowDataBound="GridView1_RowDataBound2" runat="server" Width="980px"
PageSize="2" AllowPaging="True" AllowSorting="True" OnSorting="gridViewPublishers_Sorting"
OnPageIndexChanging="gridViewPublishers_PageIndexChanging"
onrowdeleting="GridView1_RowDeleting">
<FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
<AlternatingRowStyle BackColor="LightGray" />
<Columns>
<asp:BoundField DataField="id" HeaderText="编号" ReadOnly="True" ItemStyle-Width="40"/>
<asp:BoundField DataField="姓名" HeaderText="姓名" ItemStyle-Width="80" ReadOnly="True" SortExpression="姓名"/>
<%--<asp:HyperLinkField HeaderText="姓名" DataTextField="姓名" DataNavigateUrlFields="姓名" Target="mainframe" DataNavigateUrlFormatString="ResumeAddOrUpdate.aspx?name={0}" NavigateUrl="ResumeAddOrUpdate.aspx">
</asp:HyperLinkField>--%>
<asp:BoundField DataField="性别" HeaderText="性别" ItemStyle-Width="80" ReadOnly="True"/>
<asp:BoundField DataField="出生日期" HeaderText="出生日期" ReadOnly="True" ItemStyle-Width="80"/>
<asp:BoundField DataField="工作年限" HeaderText="工作年限" ItemStyle-Width="80"/>
<asp:BoundField DataField="证件类型" HeaderText="证件类型" ItemStyle-Width="80"/>
<asp:BoundField DataField="证件号" HeaderText="证件号" ItemStyle-Width="60"/>
<asp:BoundField DataField="居住地" HeaderText="居住地" ItemStyle-Width="60"/>
<asp:BoundField DataField="Email" HeaderText="Email" ItemStyle-Width="60"/>
<asp:BoundField DataField="手机号码" HeaderText="手机号码" ItemStyle-Width="80"/>
<asp:BoundField DataField="家庭电话" HeaderText="家庭电话" ItemStyle-Width="80"/>
<asp:BoundField DataField="自我评价" HeaderText="自我评价" ItemStyle-Width="80"/>
<asp:HyperLinkField HeaderText="编辑" Text="编辑" DataNavigateUrlFields="姓名" Target="mainframe" DataNavigateUrlFormatString="ResumeAddOrUpdate.aspx?name={0}" NavigateUrl="ResumeAddOrUpdate.aspx">
</asp:HyperLinkField>
<%--<asp:CommandField HeaderText="编辑" ShowEditButton="True"></asp:CommandField>--%>
<asp:CommandField HeaderText="删除" ShowDeleteButton="True"></asp:CommandField>
</Columns>
<RowStyle ForeColor="#8C4510" BackColor="#FFF7E7" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
<PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
<HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
</asp:GridView>
/// <summary>
/// 获得连接Access数据库的字符串
/// </summary>
/// <returns></returns>
public static String GetConnection()
{
System.Web.UI.Page page = new System.Web.UI.Page();
String conn = ConfigurationSettings.AppSettings["OleDbConnectionString"].ToString() + page.Server.MapPath("~/" + ConfigurationSettings.AppSettings["AccessDbPath"].ToString());
return conn;
}