Syncfusion.XlsIO.Base
Example 


ODBCConnection Property

Gets the odbc connection
Syntax
'Declaration
 
ReadOnly Property ODBCConnection As ODBCConnection
'Usage
 
Dim instance As IConnection
Dim value As ODBCConnection
 
value = instance.ODBCConnection
ODBCConnection ODBCConnection {get;}
Remarks
If connection type is OLEDB then to customize connection properties OLEDBConnection property can be used.
Example
If the connection type is ODBC we can customize the properties of connection by accessing ODBCConnection 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 = "ODBC;DSN=MS Access;DBQ=C:\\Company\\DB\\Testing.mdb;DefaultDir=C:\\Company\\DB;FIL=MS Access;MaxBufferSize=2048;PageTimeout=5;";
            
            //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 ODBC connection
            Console.WriteLine(Connection.ODBCConnection.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.46

See Also