none
accessing Access database RRS feed

  • Question

  • Hi, im kind of new to the visual c# language and i am currently trying to access a Access database i just want to know how i should do this because i think there are quite a few ways to do it in visual c#. If you can please give me a link to a tutorials on how to do this.
    Friday, June 22, 2007 9:54 PM

All replies

  • Just know this, Access as a DB is not as good as SQL. Microsoft gives you MSDE for free; which is a smaller SQL DB. OLE connections are slow compared to a SQL connection.

     

    Here is an example on how to use Access or Excel as a DB

     

    Code Snippet

    //Excel string

    string Connectionstring = "Provider=Microsoft.Jet.OleDb.4.0; " + @"data source=C:\temp\Exceltext.xls; " + "Extended Properties=Excel 8.0;";

     

    //Access string

    string Connectionstring = "Provider=Microsoft.Jet.OleDb.4.0; " + @"data source=C:\temp\AccessTest.mdb; " + "Extended Properties=Access 8.0;";

     

    OleDbConnection cn = new OleDbConnection(Connectionstring);

    cn.Open();

    System.Data.OleDb.OleDbCommand cmd = new OleDbCommand();

    cmd.Connection = cn;

    cmd.CommandText = "CREATE TABLE EmployeeData (Id char(255), Name char(255), BirthDate date)";

    cmd.ExecuteNonQuery();

    cmd.CommandText = "INSERT INTO EmployeeData (Id, Name, BirthDate) values ('AAA', 'Andrew', '12/4/1955')";

    cmd.ExecuteNonQuery();

    cn.Close();

     

    Saturday, June 23, 2007 4:11 AM