访问连接字符串问题

本文关键字:问题 字符串 连接 访问 | 更新日期: 2023-09-27 18:15:30

我刚刚生成了一个简单的访问连接和一个简单的DataAdaptor和Dataset,以便将相关信息粘贴到gridview中。

我得到的唯一问题是它说没有错误,但带来这个消息,它不能正常运行:

"An OLE DB Provider was not specified in the ConnectionString.  An example would be, 'Provider=SQLOLEDB;'."
下面是我的代码:
public partial class Database : System.Web.UI.Page
{
   public OleDbConnection cn=new OleDbConnection(@"Data Source =Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:'Documents and Settings'jSte'Desktop'database_1.mdb; Integrated Security=true; User Instance =true");
   protected void Page_Load(object sender, EventArgs e)
   {
    OleDbDataAdapter ad = new OleDbDataAdapter ("SELECT * from CustomerDetails", cn);
    DataSet ds = new DataSet();
    ad.Fill(ds);
    GridView1.DataSource = ds;
    GridView1.DataBind();
   }

访问连接字符串问题

您有两个Data Source,这应该工作

Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:'Documents and Settings'jSte'Desktop'database_1.mdb; Integrated Security=true; User Instance=true

下面是一些例子:

https://www.connectionstrings.com/access/

您也可以使用OleDbConnectionStringBuilder来创建您的连接字符串

您的连接字符串错误。多次设置"Data Source"属性。试试这个:

public OleDbConnection cn=new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:'Documents and Settings'jSte'Desktop'database_1.mdb; Integrated Security=true; User Instance =true");

您可以这样简单地尝试一下。

public partial class Database : System.Web.UI.Page
{
   public OleDbConnection cn=new OleDbConnection(@"
                           Provider=Microsoft.Jet.OLEDB.4.0;
                           Data Source=C:'Documents and 
                           Settings'jSte'Desktop'database_1.mdb; 
                           Integrated Security=true; User Instance =true; 
                           Persist Security Info=True");  
   protected void Page_Load(object sender, EventArgs e)
   {
      OleDbCommand cmd = new OleDbCommand("SELECT * from CustomerDetails", cn);
      OleDbDataAdapter ad = new OleDbDataAdapter (cmd);
      DataSet ds = new DataSet();
      ad.Fill(ds);
      GridView1.DataSource = ds;
      GridView1.DataBind();
   }
 }