无为清净楼资源网 Design By www.qnjia.com

web.config

第一种方法:

<"1.0" encoding="utf-8""AccessConnString" value="provider=microsoft.jet.oledb.4.0;data source="/>
<add key="AccessDbPath" value="~/App_Data/guestbook.mdb"/>
</appSettings>
<connectionStrings>
<add name="AccessConnectionString" connectionString="Provider=Microsoft.Jet.OleDb.4.0;Data Source=" providerName="System.Data.OleDb"/>
<add name="Access_Path" connectionString="~/App_Data/guestbook.mdb"/>
<add name="SqlConnectionString" connectionString="Data Source=localhost;Initial Catalog=guestbook;User ID=sa;password=123456;" providerName="System.Data.SqlClient"/>
<add name="OracleConnectionString" connectionString="Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=xp2008)(PORT=1521)))(CONNECT_DATA=(SID=guandb)(SERVER=DEDICATED)));User ID=system;Password=k2763826;Unicode=True" providerName="System.Data.OracleClient"/>
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
</configuration>

第二种方法:

<"1.0" encoding="utf-8""AccessConnString" value="provider=microsoft.jet.oledb.4.0;data source="/>
<add key="AccessDbPath" value="~/App_Data/guestbook.mdb"/>
</appSettings>
<connectionStrings>
<add name="AccessConnectionString" connectionString="Provider=Microsoft.Jet.Oledb.4.0;data source="/>
<add name="Access_Path" connectionString="~/App_Data/guestbook.mdb"/>
<add name="SqlConnectionString" connectionString="Data Source=localhost;Initial Catalog=HuaRunDb;User ID=sa;password=123456;" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
</configuration>

后台 aspx.CS

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Configuration;
using System.Configuration;
using System.Data.OleDb;
using System.Data;
namespace TestOracle
{
public partial class TestConnect : System.Web.UI.Page
{
public static readonly string connStr1 = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["AccessConnectionString"].ConnectionString+ HttpContext.Current.Server.MapPath(WebConfigurationManager.ConnectionStrings["Access_Path"].ConnectionString);
public static readonly string connStr2 = System.Configuration.ConfigurationManager.AppSettings["AccessConnString"].ToString() + System.Web.HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["AccessDbPath"]) + ";";
public static readonly string connStr3 = "Provider = Microsoft.Jet.OLEDB.4.0 ;Data Source=" + HttpContext.Current.Server.MapPath("~/App_Data/guestbook.mdb");
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
OleDbConnection conn = new OleDbConnection(connStr1);
try
{
conn.Open();
string sql = "select * from GtContent";
OleDbDataAdapter myadapter = new OleDbDataAdapter(sql, conn);
DataSet ds = new DataSet();
myadapter.Fill(ds);
this.GridView1.DataSource = ds;
this.GridView1.DataBind();
this.Label1.Text = "数据库连接成功!";
}
catch (Exception ee)
{
this.Label1.Text = ee.ToString();
}
}
}
}

以上所述是小编给大家介绍的ASP.NET连接 Access数据库的几种方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!

标签:
asp.net连接access

无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com

RTX 5090要首发 性能要翻倍!三星展示GDDR7显存

三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。

首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。

据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。