C# with MS-Access

  • Thread starter Thread starter New Devil
  • Start date Start date
N

New Devil

does any body have the code for coneection of C# with MicroSoft Access
...............
and how can we use the insert , delete and modify
Thanx
(e-mail address removed)
Ibrahim
 
For connectionstrings, this was taken from www.connectionstrings.com

I haven't tested this code, but you might want to try it

string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=\somepath\mydb.mdb;Jet OLEDB:Database Password=MyDbPassword;";

System.Data.OleDb.OleDbConnection conn = new
System.Data.OleDb.OleDbConnection();
conn.ConnectionString = connectionString;

System.Data.OleDb.OleDbDataAdapter da = new
System.Data.OleDb.OleDbDataAdapter();

System.Data.OleDb.OleDbCommand selectCommand = new
System.Data.OleDb.OleDbCommand();
selectCommand.CommandText = "SELECT * FROM mydata";
selectCommand.Connection = conn;

System.Data.DataSet ds = new System.Data.DataSet();

// conn.Open();
da.Fill(ds);
// conn.Close();

It should fill ds with everything inside the table mydata
DataAdapter.Fill will open the connection and close it (if the connection
is already open it will not close it).
For insert, update and delete you would create OleDbCommands for each of
those and attach them to the dataadapter. Then for the updateprocedure
you call da.Update(ds);

Note, this is just one way to connect to a database, using DataAdapter and
DataSet, there are others that may be more suitable for your needs.
 
Back
Top