Dim strpath as string = server. mappath ("~ /Folder ")
'Create if the path of the saved file does not exist
If not directory. exists (strpath) then
Directory. createdirectory (strpath)
End if
Dim path as string = server. mappath (fileupload1.filename ))
'Upload if the file exists.
If (fileupload1.hasfile) then
Fileupload1.postedfile. saveas (PATH)
End if
'A: import the Excel file to dateview first.
'2: import the data in dateview to the database.
'Excel connection string
Dim sconnectionstring as string = "provider = Microsoft. Jet. oledb.4.0 ;"&_
"Data Source =" + path + ";"&_
"Extended properties = Excel 8.0 ;"
'Establish an Excel connection
Dim objconn as new oledbconnection (sconnectionstring)
Objconn. open ()
Dim objcmdselect as oledbcommand = new oledbcommand ("select * from [sheet1 $]", objconn)
Dim objadapter as oledbdataadapter = new oledbdataadapter ()
Objadapter. selectcommand = objcmdselect
Dim objdataset as dataset = new dataset ()
Objadapter. Fill (objdataset, "xldata ")
Dim dT as datatable = objdataset. Tables (0)
'After the table is converted, the operation can be performed immediately.
It is worth noting that you must have the permission to upload files. Therefore, add a line of code under the <Authentication mode = "Windows"/> node in Web. config.
<Identity impersonate = "true" username = "Domain Name/account" Password = "*****"/>
When publishing a website, you must add this sentence to the server. Otherwise, an error will be reported.