0

i have just produced a simple access connection and a simple DataAdaptor and Dataset to get the relevant information pasted into the gridview.

The only issue i am getting is it says no errors but brings up this message and it does not run properly:

"An OLE DB Provider was not specified in the ConnectionString.  An example would be, 'Provider=SQLOLEDB;'."

Here is my code :

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();
   }
gkrishy
  • 756
  • 1
  • 8
  • 33
Pete Tong
  • 3
  • 5

3 Answers3

0

Your connection string is wrong. You have specified the Data Source property multiple times. Try this:

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");
DavidG
  • 113,891
  • 12
  • 217
  • 223
  • I changed it and it brought up this comment: "Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done."... this was highlighted on the " ad.Fill(ds);" part? – Pete Tong Jul 30 '14 at 11:02
  • That's a different issue now. – DavidG Jul 30 '14 at 11:03
0

You have two Data Sources, this should work

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

Here are some examples:

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

You could also use the OleDbConnectionStringBuilder to create your connection-string.

Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939
  • do i still add the @"Data Source = " before that part? – Pete Tong Jul 30 '14 at 11:04
  • @Josh: why do you want to add "Data Source" twice? – Tim Schmelter Jul 30 '14 at 11:05
  • I changed it and it brought up this comment: "Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done."... this was highlighted on the " ad.Fill(ds);" part? – Pete Tong Jul 30 '14 at 11:05
  • I don't know that error, but maybe this question helps: http://stackoverflow.com/questions/51589/how-do-i-fix-the-multiple-step-ole-db-operation-errors-in-ssis – Tim Schmelter Jul 30 '14 at 11:07
  • Your article helped me i had the wrong clause at the end of data source had to change it to "Persist Security Info=False;" as i had no security present for this test database. Thanks A lot – Pete Tong Jul 30 '14 at 11:11
0

You may simply try in this way.

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();
   }
 }

Please see here for some more clarification.

Community
  • 1
  • 1
gkrishy
  • 756
  • 1
  • 8
  • 33