Syncfusion.XlsIO.Base
Example 


Name Property (IConnection)

Represent the connection name.
Syntax
'Declaration
 
Property Name As String
'Usage
 
Dim instance As IConnection
Dim value As String
 
instance.Name = value
 
value = instance.Name
string Name {get; set;}
Example
The following code illustrates how name can be set and accessed for the connection.
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";
            
            // Import data to the sheet from the database
            table.Refresh();
            
            //Get Name
            Console.WriteLine(Connection.Name);
            
            //Apply AutoFit
            worksheet.UsedRange.AutofitColumns();
            
            //Save and Dispose
            workbook.SaveAs("Tables.xlsx");
            workbook.Close();
            Console.ReadKey();
        }
    }
}
//Output will be
//Connection1
AssemblyVersion

Syncfusion.XlsIO.Base: 17.1460.0.32

See Also