среда, 6 июля 2011 г.

How to select column from Excel sheet


OleDbConnection connection = null;
        String sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + @"c:\Book.xls" + ";" + "Extended Properties=Excel 8.0;";
        DataTable dtCH = new DataTable();
        connection = new OleDbConnection(sConnectionString);
        OleDbCommand command = new OleDbCommand("Select column1,column2 FROM [Sheet1$]", connection);
        connection.Open();
        dtCH = new DataTable("Table");
        OleDbDataReader db_reader = command.ExecuteReader();

        dtCH.Load(db_reader);
        DataTable table = dtCH;

        connection.Close();

Комментариев нет: