Thursday, 6 March 2014

Create a connection with MSAcess and open the conection object.

1) First add "using System.Data.OleDb;" at to top of the CS file.
2) Create connection string and open connection.
For access 2007

string ConnStr = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\abc.mdb;Jet OLEDB:Database Password=password";

OleDbConnection MyConn = new OleDbConnection(ConnStr);

3) Open this connection.

MyConn.Open();


4) Create object for command and reader to get the data from access database.

OleDbCommand Cmd = new OleDbCommand(StrCmd, MyConn);;
OleDbDataReader ObjReader = Cmd.ExecuteReader();


5) Now lood through the reader object to get the data

if (ObjReader != null)
{
}

6) After completing the processing

ObjReader.Close();
MyConn.Close();

No comments:

Post a Comment