Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
3
Reply
How to select Columns from excel sheet
b b
Dec 13 2010 5:32 AM
11k
Reply
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
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
3
)
Next Recommended Forum
how to upload image in gridview through database in asp.net
microsoft visual basic error