Monday, 23 January 2012

Connecting to MS Access Database in ASP .NET

Connecting to MS Access Database in ASP .NET

Code for Connecting to Access
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.OleDb;
public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {   
        //Connection String
        OleDbConnection NewConnection = new
 OleDbConnection(@"Provider=Microsft.Jet.OLEDB.4.0; Data Source = c:\newDtabse.mdb");
        NewConnection.Open();     //Connection Open 
    }
}
newDtabse.mdb is the name of database.



How to know about your OleDBConnection

public partial class _Default : System.Web.UI.Page 
{
 protected void Page_Load(object sender, EventArgs e)
 {
  OleDbConnection NewConnection = new
  OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0; Data Source = D:\newDtabse.mdb");
  NewConnection.Open();
  Label1.Text = NewConnection.State.ToString();
  Label2.Text = NewConnection.ServerVersion.ToString();
  Label3.Text = NewConnection.Provider.ToString();
 }
}
emp_tbl table data show in a gridview.
Post a Comment