Saliha Uzel
Saliha Uzel

Reputation: 151

Select columns from excel file by using C#

for the query:

OleDbDataAdapter adapter = new OleDbDataAdapter("Select * from[" + sheetName + "$] where [BARKOD] is not null", Connection);

can I get the data of specific columns for example column 1(header=ID) and 3(header=NAME) instead of whole table(*)?

Upvotes: 0

Views: 1407

Answers (1)

Tim Schmelter
Tim Schmelter

Reputation: 460028

You could select the column name first, for example:

DataTable schemaColTable = Connection.GetOleDbSchemaTable(OleDbSchemaGuid.Columns, null);
String firstColumnName = schemaColTable.Select(null, "TABLE_NAME,ORDINAL_POSITION", DataViewRowState.CurrentRows)[0]["COLUMN_NAME"].ToString();

Then you use these column names for your queries.

Upvotes: 1

Related Questions