Hello, I am trying to translate an Excel file into my dataGridView file and it has problems with the column name, because the way to format the Excel file consists of two setting cells for the rest of the document. However, the column names are actually on row number 2. How to skip the first row in the file so that the columns in the dataGridView display cell values from the second row?
Current code:
var connectionString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0; data source={0}; Extended Properties=Excel 8.0;", openFileDialog1.FileName); string query = String.Format("select * from [{0}$]", "Sheet1"); var adapter = new OleDbDataAdapter(query, connectionString); DataSet ds = new DataSet(); adapter.Fill(ds); DataTable dt = ds.Tables[0]; techGrid.DataSource = dt;
Just as Thit Lwin commented. Delete the first line before setting dt as the data source.
DataRow row = dt.Rows[0]; dt.Rows.Remove(row); techGrid.DataSource = dt;
- Excel , . . OPENQUERY . , tempdb , , .
:
string query = String.Format("select * from [{0}$]", "Sheet1");
string query = String.Format("select * from [{0}${1}]", "Sheet1","A2:ZZ");
, , . , , . ConnectionStrings.com:
Provider=Microsoft.ACE.OLEDB.12.0; Data Source=myOldExcelFile.xls; Extended Properties="Excel 12.0;HDR=YES";
"HDR = Yes"; , , . "HDR = No;" .
, ,
IEnumerable<DataRow> newRows = dt.AsEnumerable().Skip(numberOfRows); DataTable dt2 = newRows.CopyToDataTable();
Source: https://habr.com/ru/post/1545041/More articles:Laravel form validation is unique using two fields - phpJava wildcard mask is incompatible - javaangular ui.grid [[object HTMLDivElement]] will be displayed instead of the data in each cell - angular-uiHow do default template arguments work? - c ++How to import Excel data to SQL Server using ASP.NET C # where table data does not start on the first line? - c #Visual Studio Custom Property Macros in C # - macrosPHP - check if a string is a multibyte alphanumeric character - phpPosition text on the chart with the reverse axis in ggplot2 - rJava ProcessBuilder not working with wkhtmltopdf - javaпочему webappclassloader не собирает мусор? - javaAll Articles