Import SQL Server using ASP. NET Excel

Source: Internet
Author: User

The. aspx. cs file call code for importing SQL Server via ASP. NET Excel:

 
 
  1. Protected VoidBtnExport_Click (ObjectSender, EventArgs e)
  2. {
  3. StringFilepath =This. FileUpload. PostedFile. FileName;
  4. // This part gets the file name without a path, so it is likely that the excel file cannot be found, so if there is a problem, you can write it like this: 
  5.  
  6. // String fileName = fileUpload. PostedFile. FileName; 
  7. // FileUpload. PostedFile. SaveAs (Server. MapPath ("upfile") + "\" + fileName ); 
  8. // String filepath = Server. MapPath ("upfile") + "\" + fileName; 
  9.  
  10. If(Filepath! ="")
  11. {
  12. If(This. TxtTableName. Text! ="")
  13. {
  14. If(Filepath. Contains ("Xls"))
  15. {
  16. IntResult = ets. ImportSql (filepath,This. TxtTableName. Text );
  17.  
  18. If(Result = (Int) ExcelToSQL. ImportState. tableNameError)
  19. Ets. Alert ("This table name does not exist in the data! ");
  20. Else If(Result = (Int) ExcelToSQL. ImportState. excelFormatError)
  21. Ets. Alert ("The Excel format cannot be read correctly! ");
  22. Else If(Result = (Int) ExcelToSQL. ImportState. fieldMatchError)
  23. Ets. Alert ("The fields in Excel do not match those in SQL Server! ");
  24. Else If(Result = (Int) ExcelToSQL. ImportState. dataTypeError)
  25. Ets. Alert ("An error occurred while converting the data type! ");
  26. Else If(Result = (Int) ExcelToSQL. ImportState. right)
  27. {
  28. Ets. Alert ("Import successful");
  29. }
  30. }
  31. ElseEts. Alert ("The uploaded file type must be an excel file! ");
  32. }
  33. ElseEts. Alert ("The table name cannot be blank! ");
  34. }
  35. ElseEts. Alert ("No file is selected for upload! ");
  36. }
  37.  

Import SQL Server using ASP. NET Excel. aspx front-end code

 
 
  1. <Form id ="Form1"Runat ="Server">
  2. <Div>
  3. <Asp: Label ID ="Label1"Runat ="Server"Text ="Path"></ Asp: Label>
  4. & Nbsp; <asp: FileUpload ID ="FileUpload"Runat ="Server"Width ="443px"/> <Br/>
  5. <Asp: Label ID ="Label2"Runat ="Server"Text ="Database table name"></ Asp: Label >& nbsp;
  6. <Asp: TextBox ID ="TxtTableName"Runat ="Server"></ Asp: TextBox ><br/>
  7. <Asp: Button ID ="BtnExport"Runat ="Server"Text ="Import to SQL"OnClick ="BtnExport_Click"/>
  8. </Div>
  9. </Form>

The call operation for importing SQL Server from ASP. NET Excel is introduced here. I hope to help you understand the call operation for importing SQL Server from ASP. NET Excel.

  1. Dynamic Implementation of Excel in ASP. NET
  2. Notes on Excel operations using ASP. NET
  3. Analysis on the lifecycle of ASP. NET Server controls
  4. Analysis on three methods of ASP. NET reading Excel files
  5. Import SQL Server database using ASP. NET Excel

Related Article

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.