Syncfusion.XlsIO.Base
Example 


OLEDBConnection Property

Gets the oledb connection.
Syntax
'Declaration
 
ReadOnly Property OLEDBConnection As OLEDBConnection
'Usage
 
Dim instance As IConnection
Dim value As OLEDBConnection
 
value = instance.OLEDBConnection
OLEDBConnection OLEDBConnection {get;}
Remarks
If connection type is ODBC then to customize connection properties ODBCConnection property can be used.
Example
If the connection type is OLEDB we can customize the properties of connection by accessing OLEDBConnection property. Here for example, we get the command text and print it to console.
using Syncfusion.XlsIO;
using System;
            
class Program
{
    static void Main()
    {
        using (ExcelEngine excelEngine = new ExcelEngine())
        {
            //Create worksheet
            IApplication application = excelEngine.Excel;
            application.DefaultVersion = ExcelVersion.Excel2013;
            IWorkbook workbook= application.Workbooks.Create(1);
            IWorksheet worksheet = workbook.Worksheets[0];
            
            //Set Connection string for DataSource
            string ConnectionString = "OLEDB;Provider=Microsoft.JET.OLEDB.4.0;Password=\"\";User ID=Admin;Data Source=AccessDB.mdb";
            
            //Add a connection to the workbook
            IConnection Connection = workbook.Connections.Add("Connection1", "Sample connection with MsAccess", ConnectionString, "", ExcelCommandType.Sql);
            
            //Add a QueryTable to sheet object
            IListObject table = worksheet.ListObjects.AddEx(ExcelListObjectSourceType.SrcQuery, Connection, worksheet.Range["A1"]);
            
            //Set Command Text for the Connection
            table.QueryTable.CommandText = "Select * from tbltest";
            
            //Set connection description
            Connection.Description = "Sample Connection";
            
            // Import data to the sheet from the database
            table.Refresh();
            
            //Get Command Text from OLEDB connection
            Console.WriteLine(Connection.OLEDBConnection.CommandText);
            
            //Apply AutoFit
            worksheet.UsedRange.AutofitColumns();
            
            //Save and Dispose
            workbook.SaveAs("Tables.xlsx");
            workbook.Close();
            Console.ReadKey();
        }
    }
}
//Output will be
//Select * from tbltest
AssemblyVersion

Syncfusion.XlsIO.Base: 17.2460.0.34

See Also