b b

b b

  • NA
  • 53
  • 0

How to select Columns from excel sheet

Dec 13 2010 5:32 AM
Hi All,

I want to select few columns from Excel Sheet to datatable(not whole Excel sheet) using C# .net. Can anyone help me.

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

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

connection.Close();


I am using the above codes and its shoeing all values from Excel file to Datatable. But i want to show only few columns from Excel to Datatable.


Regards,
B

Answers (3)