OleDbConnectionStringBuilder builder = new OleDbConnectionStringBuilder(); builder.Provider = "Microsoft.Jet.OLEDB.4.0"; builder.DataSource = @"C:\Data\MyAccessDB.mdb"; string connectionString = builder.ToString(); Console.WriteLine(connectionString);
string connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Data\MyExcelFile.xlsx;Extended Properties='Excel 12.0 Xml;HDR=YES;'"; OleDbConnectionStringBuilder builder = new OleDbConnectionStringBuilder(connectionString); builder["HDR"] = "NO"; connectionString = builder.ToString(); Console.WriteLine(connectionString);This example starts by defining a connection string that connects to an Excel file with headers. It then creates a new instance of the OleDbConnectionStringBuilder class and passes the connection string to its constructor to initialize its state. The code modifies the "HDR" property to be "NO" and then calls the ToString method to get the updated connection string. In both examples, the OleDbConnectionStringBuilder class is used to modify a connection string and the ToString method is used to get the final connection string value. The package library that contains the OleDbConnectionStringBuilder class is System.Data.dll, which is included in the .NET Framework.