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
Karthikeyan AnbarasanPosted Apr 8, 2011, 2:55 AM
vijayPosted Mar 25, 2011, 9:49 AM
try this link to get a excel file into datatable...
http://vbdotnetaddict.blogspot.com/2011/01/import-excel-table-into-sql-table.html
After getting the excel file into datatable and you can select a particular column from the data table..Its very easy steps to select a any column from datatable...
Krishna GaradPosted Dec 30, 2010, 5:53 AM