Recently I used C # To read the database in an Excel table.
Dataset DS = new dataset ();
Txtfile1.text = openfiledialog1.filename;
Oledbconnection xlsconnection = new oledbconnection (
@ "Provider = Microsoft. Jet. oledb.4.0; Data Source =" + txtfile1.text + "; extended properties = Excel 8.0 ;");
// select Configuration data from Excel file that make by customer
oledbdataadapter da_db = new oledbdataadapter ("select * from [DBS $]", xlsconnection );
// fill data into dataset
da_db.fill (DS, "DBs");
This. datagrid1.datasource = Ds;
The result encountered a strange bug where the values in one column were often incorrect. Later I found that if I runProgramThe read data is correct. If you do not open an Excel table, the value read from this column is null.
Someone instructed me to create an Excel file, manually enter the column names, and then paste the data to read the new table. I tried it, but it was okay, speechless.
Later, we found that sometimes there are too many empty rows and the rows will become null.