Today, I accidentally uploaded the Excel Data to SQL Server.
Yu Feng said that it is essential to keep a low profile to learn a technology. It cannot be known that it was just a meeting ~~~~~~~~ Hey !!!
If (Fileupload1.hasfile) // If you have selected the Browse button of the upload control, the file is successfully browsed.
{
This . Fileupload1.saveas ( " D: \ temp \\ " + Fileupload1.filename ); // To save the file to the server directory, You need to modify fileupload1.filename Based on the server's actual situation to automatically obtain the upload file name.
SDH. dbexecutesql ( " Insert into larbor select * From OpenRowSet ('Microsoft. Jet. oledb.4.0 ', 'excel 8.0; HDR = yes; database = D: \ temp \\ " + Fileupload1.filename + " ', Sheet1 $) " ); // The name of Sheet 1 is the name of the current page of the Excel table. larbor is the name of the table accepted
Response. Write ( " <SCRIPT> alert ('import successful! '); </SCRIPT> " );
}
Else
{
Response. Write ("<SCRIPT> alert ('import failed! '); </SCRIPT>");
}
By default, sql2005 does not enable the ad hoc distributed queries component.
Database execution:
Exec Sp_configure show advanced options, 1
Go
Reconfigure
Go
Exec Sp_configure ad hoc Distributed Queries, 1
Go
Reconfigure
Go