Connect Access 2007 from code


protected void Page_Load(object sender, EventArgs e)

{

System.Data.

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

string strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Server.MapPath(".") + "\\App_Data\\Database1.accdb;" ;

System.Data.OleDb.

OleDbDataAdapter objDataAdapter = new System.Data.OleDb.OleDbDataAdapter("SELECT col1, col2 FROM [myTable1]", strConn);

objDataAdapter.Fill(objDs);

GridView1.DataSource = objDs.Tables[0].DefaultView;

GridView1.DataBind();

}

Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s