In view of the fact that educational affairs are generally manual input of student information, we are prepared to design an Excel document, such as a database, for students who do not have an objective understanding of the database. Combined with all kinds of online Daniel's comprehensive version baked.
The first concrete realization thought is as follows:
1. Use the FileUpload control first to upload an Excel file to a folder on the server fuload.
2. Use OLE DB to read the Excel file that has been uploaded to the server and read the Excel file as a database. In the contact database statement, the data source is the physical path to the file on the server
3. Returns the data read in the second step as a DataTable object.
4. Iterates through the DataTable object and then queries the SQL Server database for the existence of the data. If it exists, it can be updated or not processed, or if it does not, insert the data.
Note: When traversing a DataTable, use DT. rows[i]["Name"]. ToString (); Name is the header of the Name column, so the order of the columns in Excel is irrelevant. Of course, if you know the name of each table header in Excel column. If the columns in Excel are in a fixed order, you can do so in the following code.
The implementation of the method is clear, in the design of this feature is to note that the "external table is not the expected format" error, here is mainly the version of Excel problem
As on only the Excel 03-07 version is supported, later versions of Excel are saved as compatibility mode. Of course, I found in the programming process some examples will add physical address in the MapPath, the individual is not very recommended, this method may open a fixed path, it is not easy to feel.
Code a little, the internet has, need to integrate themselves.
Good example, do not bother to add links, directly sticky web address.
Http://blog.sina.com.cn/s/blog_5fe13c500100cwoh.html
Http://www.cnblogs.com/ZQiuMei/archive/2012/12/28/2837065.html
Http://www.cnblogs.com/kingkongv/archive/2012/08/26/2657436.html
http://blog.csdn.net/cpcpc/article/details/7029446
Http://blog.sina.com.cn/s/blog_77f88ea60100zi64.html
They're good.
ASP. NET Import Excel document