C#连接access数据库失败,改修改的都修改了,但还是连不上,请各路高手指点。
1个回答
展开全部
我记得很麻烦!
这是webconfig文件里面的内容
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="conn" value="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=ly1.mdb;"/>
</appSettings>
<connectionStrings>
</connectionStrings>
<system.web>
<compilation debug="true" />
<authentication mode="Windows" />
</system.web>
</configuration>
Default.aspx.cs文件下
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb; 这个行是新加的
public partial class _Default : System.Web.UI.Page
{
public OleDbConnection connoled()
{
string oled = ConfigurationManager.AppSettings["conn"].ToString();
OleDbConnection myconn = new OleDbConnection(oled);
return myconn;
}
protected void Button1_Click(object sender, EventArgs e)
{
OleDbConnection myconn = connoled();
myconn.Open();
}
}
这是webconfig文件里面的内容
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="conn" value="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=ly1.mdb;"/>
</appSettings>
<connectionStrings>
</connectionStrings>
<system.web>
<compilation debug="true" />
<authentication mode="Windows" />
</system.web>
</configuration>
Default.aspx.cs文件下
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb; 这个行是新加的
public partial class _Default : System.Web.UI.Page
{
public OleDbConnection connoled()
{
string oled = ConfigurationManager.AppSettings["conn"].ToString();
OleDbConnection myconn = new OleDbConnection(oled);
return myconn;
}
protected void Button1_Click(object sender, EventArgs e)
{
OleDbConnection myconn = connoled();
myconn.Open();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询