AshishvermaMCA wrote in comment:
I am using this code to take data from excel file-
oledbConn.Open();
object dt = oledbConn.GetSchema("Tables").Rows[0]["TABLE_NAME"];
OleDbCommand cmd = new OleDbCommand("SELECT * FROM [" + dt.ToString() + "]", oledbConn);
OleDbDataAdapter oleda = new OleDbDataAdapter();
oleda.SelectCommand = cmd;
oleda.Fill(ds, "WellCareMCD");
oledbConn.Close();
Replace:
OleDbCommand cmd = new OleDbCommand("SELECT * FROM [" + dt.ToString() + "]", oledbConn);
with:
OleDbCommand cmd = new OleDbCommand("SELECT ColumnName1, ColumnName2, ColumnNameX FROM [" + dt.ToString() + "]", oledbConn);
EDIT
For dynamic version, please see:
Excel Add-in Framework for Validating and Exporting Data[
^]
It might be helpful too:
Reading an Excel Sheet into a DataTable, generic method[
^]