ADO/ADO.NET - how to solve the warning Ms Acess database already exit in

Asked By Bhanuprakash T.R on 20-Jun-12 03:10 AM
Hello sir , i placed one button(Write Db). if i click write db means what are the data in sdf file is transform to mdf file. if i run first time means i can able to do it. if i again run means it shows an error the database already created. if the database is already is there means it will delete and created new one . if database is not there means it will create new one..please how can i implement if else condition please tell me

i try this code
       ADOX.CatalogClass cat = new ADOX.CatalogClass();
        cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;" +
        "Data Source=C:/StockManagement/StockManagement.mdb;" +
        "Jet OLEDB:Engine Type=5");
        MessageBox.Show("database created successfully");
        cat = null;
        SqlCeConnection con = new SqlCeConnection("Data Source=" + textbox1.text.toString+ "");
        SqlCeDataAdapter da = new SqlCeDataAdapter("select * from purchaseOrder", con);
        DataTable dt = new DataTable();
        OleDbConnection con1 = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/StockManagement/StockManagement.mdb");
        OleDbCommand cmd = con1.CreateCommand();
        cmd.CommandText = "create table purchaseOrder(barcode varchar(150),Actualqty varchar(150),LocationID varchar(100))";

        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() + "')";



[)ia6l0 iii replied to Bhanuprakash T.R on 20-Jun-12 12:51 PM
This should be easy with System.IO giving us the File class.  There is an Exists method that returns a boolean after checking if the file exists. Just provide a path, and it will do wonders for you. 

The code would be on following lines:
If File.Exists("C:/StockManagement/StockManagement.mdb") Then
 'Database already exists
'Database does not exist.
End If

Do not forget to add "Imports System.File.IO" at the top of your class.

Good one :-; Thank you.