I'm loading the excel records to a datatable. When this table is bound to a gridview, I see an additional column 'F1' and also an additional row with empty data. How can I prevent this.
For example, the excel sheet has these records:
Name L1 L2
----------------
abc 2 4
def 3 3
When bound to grid view, I see as an additional column(F1) and a row(3)
S.No Name L1 L2 F1
-------------------------
1 abc 2 4
2 def 3 3
3
ASPX:
<asp:GridView ID="gv" runat="server" AutoGenerateColumns="true">
<columns>
<asp:TemplateField HeaderText="S.No">
<ItemTemplate>
<%#Container.DataItemIndex+1%>
</ItemTemplate>
</asp:TemplateField>
</columns>
</asp:GridView>
C#
DataTable dtExcel = new DataTable();
DataTable dt = new DataTable();
OleDbConnection conn = new OleDbConnection(connString);
conn.Open();
dtExcel = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,null);
string qry = "select * from [Sheet1$]";
OleDbDataAdapter da = new OleDbDataAdapter(qry,conn);
da.Fill(dt);
conn.Close();
gv.DataSource=dt;
gv.DataBind();
Would just deleting the last column be a good approach.Why is it coming in the first place.
Another option would be deleting the column with name 'F1' in the DataTable, but what if that may also be a name of one of the original columns like L1, L2, ....