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());
    }
This article has been dead for over six months. Start a new discussion instead.