I am export the data from excel sheet 1 to tab page 1 and then sheet2 to tab page 2 and so on. each datagridview has a checkbox column. How do i do tis using only one datagridview.
The problem is the excel file is imported with column headings. If the user clicks on header by error it gives an error notification. Must be a non-negative number etc.
So the first row of the import to datagridview is headings.
System.Data.OleDb.OleDbConnection MyConnection;
//System.Data.DataSet DtSet;
System.Data.OleDb.OleDbDataAdapter MyCommand;
MyConnection = new System.Data.OleDb.OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" +
"C:\\Users\\shabz\\Documents\\PriceListMaster.xlsx" + ";Extended Properties='Excel 12.0 XML;HDR=YES;IMEX=1';");
MyCommand = new System.Data.OleDb.OleDbDataAdapter("select * from [allpurpose$]", MyConnection);
//MyCommand.TableMappings.Add("Table", "Net-informations.com");
DataTable dt = new DataTable();
MyCommand.Fill(dt);
dataGridView1.DataSource = dt;
MyConnection.Close();
this.dataGridView1.Columns[7].Visible = false;
this.dataGridView1.Columns[1].Width = 180;
this.dataGridView1.Columns[2].Width = 315;
this.dataGridView1.Columns[5].DefaultCellStyle.Format = "0.00";
ProdCode Product Pack Qty Disc TaxAmt Total
1234 soap 1 0 15 0 0
That is my excel sheet.
In my TabControl1 i create a TabPage1. A datagridview1 is inserted and i added a checkboccolumn which is not visible
Is there an easier way to create headers and then import excel that way the first row will be a header and at the moment it is Header from.