In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-13 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
In this issue, the editor will bring you about how to achieve Excel to MSSQL in ASP.NET data import. The article is rich in content and analyzes and describes for you from a professional point of view. I hope you can get something after reading this article.
What is the process of implementing Excel to MSSQL? What should I pay attention to?
When you do a website project, you may encounter the need to import the ASP.NET data from the Excel file into the SQL Server database. Excel is also regarded as a database. After using OleDb connection, you can read the data and then write to the SQL Server database connected with SqlClient. There is no technical difficulty.
But one problem that needs to be considered is that the environment in which the system is installed is generally a dedicated sql server server + web server + client, and the Excel file is often imported on the client side. If you directly use SQL statements to read, because SQL runs on the web server and can not read the Excel address of the client, there will be an error.
Now that we know the cause of the error, there is a solution:
1. Upload the Excel of the client to a folder on the web server, and be sure to set the "write" permission for the network user to the folder.
2. Use OleDb+ SQL statement to read the Excel file on the web server
3. Import the read ASP.NET data into the SQL Server database
4. Delete the temporary Excel on the web server
Some of the codes are as follows:
String filename = FileUpload1.PostedFile.FileName.Substring (FileUpload1.PostedFile.FileName.LastIndexOf ("\\")); FileUpload1.PostedFile.SaveAs (Server.MapPath ("fileupload\") + filename); / / upload file string conn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath ("fileupload\") + filename + "; Extended Properties=Excel 8.0"; string sqlin = "SELECT * FROM [Sheet2 $]"; OleDbCommand olecommand = new OleDbCommand (sqlin, new OleDbConnection (conn)) OleDbDataAdapter adapterin = new OleDbDataAdapter (olecommand); DataSet dsin = new DataSet (); adapterin.Fill (dsin); DataTable dtin = dsin.Tables [0]; / / Connect and read Excel data for (I = 3; I
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.