Saturday 31 May 2014

Read Excel file and convert into Dataset

   OleDbConnection connection = new OleDbConnection();
        string path = string.Concat(Server.MapPath("../Uploaded Folder/chart.xls"));

      // Excle Read Connection String for open office
        string excelConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + path + "; Extended Properties=Excel 8.0;";
     
        connection.ConnectionString = excelConnectionString;
        OleDbCommand command = new OleDbCommand("select * from [Sheet1$]", connection);
        OleDbCommand command2 = new OleDbCommand("select * from [Sheet2$]", connection);
        connection.Open();
        // Create DbDataReader to Data Worksheet
        DbDataReader dr = command.ExecuteReader();
        DbDataReader dr2 = command2.ExecuteReader();
     

        dt.Load(dr);
        dt1.Load(dr2);
        ds = new DataSet();
        ds.Tables.Add(dt);
        ds.Tables.Add(dt1);

No comments:

Post a Comment

रूस-यूक्रेन संकट लाइव: भारतीयों को 'उपलब्ध किसी भी साधन' के माध्यम से कीव को तत्काल छोड़ने के लिए कहा

  रूस यूक्रेन संकट लाइव: कीव में भारतीय दूतावास ने मंगलवार को जारी एक एडवाइजरी में भारतीयों को  'किसी भी उपलब्ध साधन' के माध्यम से क...