i want to connect asp.net 2005 with access .
now i need for the code do do this connection

Create a variable Like x
Then
x="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Program Files\office.mdb"
Note :C:\Program Files\office.mdb By replacing it put your datasource And then try this

thnx for reply :D

what about the full code & the veriables when i want to do insert and the code to execute the query ???

There are two functions for generating the conn string depending on the version of access, which can be determined by the file extension or various other ways.

public static string BuildAccessConnectionString(string Filename, string Username, string Password, string DatabasePassword)
    {
      return string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='{0}';User Id={1};Password={2};Jet OLEDB:Database Password={3};",
                                   Filename.Replace("'", "''"),
                                   Username,
                                   Password,
                                   DatabasePassword);
    }
    public static string BuildAccess2007ConnectionString(string Filename, string DatabasePassword)
    {
      return string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source='{0}';Persist Security Info=False;Jet OLEDB:Database Password={1};",
                                 Filename.Replace("'", "''"),
                                 DatabasePassword);
    }
    private void simpleButton3_Click(object sender, EventArgs e)
    {
      string connStr = BuildAccessConnectionString(@"C:\data\CustList01.mdb", string.Empty, string.Empty, string.Empty);
      DataTable result = new DataTable();
      using (OleDbConnection conn = new OleDbConnection(connStr))
      {
        conn.Open();
        using (OleDbCommand cmd = new OleDbCommand(@"Select * From [CustList01]", conn))
        {
          using (OleDbDataReader dr = cmd.ExecuteReader())
          {
            result.Load(dr);
          }
        }
        conn.Close();
      }
      //Work with table
      MessageBox.Show(result.Rows.Count.ToString());
    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.