How to Read Excel File RRS feed

  • Question

  • User1953918952 posted

    I have upload an excel file..Now i want to read cell values and store these cell values in an array and assign these array values to a textbox

    Can u please help me how it can be possible



    Sunday, December 8, 2013 3:43 AM

All replies

  • User1508394307 posted

    For example,

    string sourcePath = @"C:\\Users\\jojisheen\\Desktop\\Book1.xls";
    string ExcelConStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + sourcePath + ";Extended Properties=Excel 8.0;HDR={1}'";
    // Create Connection to Excel Workbook
    using (OleDbConnection connection = new OleDbConnection(ExcelConStr))
    OleDbCommand command = new OleDbCommand("Select * FROM [Sheet1$]", connection);
    // Create DbDataReader to Data Worksheet
    using (DbDataReader dr = command.ExecuteReader())
    // SQL Server Connection String
    string sqlConnectionString = @"Data Source=JOJISHEEN-PC\SQLEXPRESS;Initial Catalog=ForExcel;Integrated Security=True";
    // Bulk Copy to SQL Server
    using (SqlBulkCopy bulkCopy = new SqlBulkCopy(sqlConnectionString))
    bulkCopy.DestinationTableName = "T_ImportExcel";
    MsBx("Data Exoprted To Sql Server Succefully");
    objCmd = new SqlCommand("Select * from T_ImportExcel", objConn);
    objDa = new SqlDataAdapter(objCmd);
    DataSet ds = new DataSet();
    grdvw.DataSource = ds;
    grdvw.DataSourceID = String.Empty;

    Hope this helps.

    Sunday, December 8, 2013 3:49 AM