ADO/ADO.NET - No such interface supported - Asked By Bhanuprakash T.R on 21-Jun-12 01:25 AM

Hello sir i placed one  button(Writedb) click means . what are the data in sdf file . whole data inserted into access sheet. it is also working fine. the file was stored in the path C:/StockManagement/StockManagement.mdb. if i compile first time means it was created successfully. if again compile means it shows an runtime error is database already exist. now i want solution was if the database is already is there means delete the database and created new one.if the database is not there created new one..please tell me the solution
i try this code
//button click
if (File.Exists(@"C:/StockManagement/StockManagement.mdb"))
      {
}
else{

    MessageBox.Show("file was trying to create");
          Directory.CreateDirectory("C:/StockManagement");
          ADOX.CatalogClass cat = new ADOX.CatalogClass();
          string createStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:/StockManagement/StockManagement.mdb;";
          cat.Create(createStr);
      MessageBox.Show("database created successfully");
      cat = null;
      MessageBox.Show(pra);
      SqlCeConnection con = new SqlCeConnection("Data Source=" + pra + "");
      SqlCeDataAdapter da = new SqlCeDataAdapter("select * from purchaseOrder", con);
      DataTable dt = new DataTable();
      da.Fill(dt);
      OleDbConnection con1 = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/StockManagement/StockManagement.mdb");
      con1.Open();
      OleDbCommand cmd = con1.CreateCommand();
      cmd.CommandText = "create table purchaseOrder(barcode varchar(150),Actualqty varchar(150),LocationID varchar(100))";
      cmd.ExecuteNonQuery();


      for (int i = 0; i < dt.Rows.Count; i++)
      {
        cmd.CommandText = "insert into purchaseOrder (barcode,Actualqty,LocationID) values('" + dt.Rows[i]["barcode"].ToString() + "','" + dt.Rows[i]["Actualqty"].ToString() + "','" + dt.Rows[i]["LocationID"].ToString() + "')";


        cmd.ExecuteNonQuery();

      }

}

i get run time error as No such interface supported in this line cat.Create(createStr); please tell me how to solve the problem
Vikram Singh Saini replied to Bhanuprakash T.R on 21-Jun-12 09:53 PM
Replace following code line:

ADOX.CatalogClass cat = new ADOX.CatalogClass();
      string createStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:/StockManagement/StockManagement.mdb;";
      cat.Create(createStr);


by the following code:

ADOX.Catalog cat = new ADOX.Catalog();

string createStr = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:/StockManagement/StockManagement.mdb;";

cat.Create(createStr);

 
Note: The first line of modified code is important. We have modified the code line with interface type by removing suffix 'Class'. (More details on same at http://blogs.msdn.com/b/mshneer/archive/2009/12/07/interop-type-xxx-cannot-be-embedded-use-the-applicable-interface-instead.aspx)


I tested the code and it worked fine. Do response back if it helped or not.