C # Excel reading bug

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.