The. aspx. cs file call code for importing SQL Server via ASP. NET Excel:
- Protected VoidBtnExport_Click (ObjectSender, EventArgs e)
- {
- StringFilepath =This. FileUpload. PostedFile. FileName;
- // 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:
-
- // String fileName = fileUpload. PostedFile. FileName;
- // FileUpload. PostedFile. SaveAs (Server. MapPath ("upfile") + "\" + fileName );
- // String filepath = Server. MapPath ("upfile") + "\" + fileName;
-
- If(Filepath! ="")
- {
- If(This. TxtTableName. Text! ="")
- {
- If(Filepath. Contains ("Xls"))
- {
- IntResult = ets. ImportSql (filepath,This. TxtTableName. Text );
-
- If(Result = (Int) ExcelToSQL. ImportState. tableNameError)
- Ets. Alert ("This table name does not exist in the data! ");
- Else If(Result = (Int) ExcelToSQL. ImportState. excelFormatError)
- Ets. Alert ("The Excel format cannot be read correctly! ");
- Else If(Result = (Int) ExcelToSQL. ImportState. fieldMatchError)
- Ets. Alert ("The fields in Excel do not match those in SQL Server! ");
- Else If(Result = (Int) ExcelToSQL. ImportState. dataTypeError)
- Ets. Alert ("An error occurred while converting the data type! ");
- Else If(Result = (Int) ExcelToSQL. ImportState. right)
- {
- Ets. Alert ("Import successful");
- }
- }
- ElseEts. Alert ("The uploaded file type must be an excel file! ");
- }
- ElseEts. Alert ("The table name cannot be blank! ");
- }
- ElseEts. Alert ("No file is selected for upload! ");
- }
-
Import SQL Server using ASP. NET Excel. aspx front-end code
- <Form id ="Form1"Runat ="Server">
- <Div>
- <Asp: Label ID ="Label1"Runat ="Server"Text ="Path"></ Asp: Label>
- & Nbsp; <asp: FileUpload ID ="FileUpload"Runat ="Server"Width ="443px"/> <Br/>
- <Asp: Label ID ="Label2"Runat ="Server"Text ="Database table name"></ Asp: Label >& nbsp;
- <Asp: TextBox ID ="TxtTableName"Runat ="Server"></ Asp: TextBox ><br/>
- <Asp: Button ID ="BtnExport"Runat ="Server"Text ="Import to SQL"OnClick ="BtnExport_Click"/>
- </Div>
- </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.
- Dynamic Implementation of Excel in ASP. NET
- Notes on Excel operations using ASP. NET
- Analysis on the lifecycle of ASP. NET Server controls
- Analysis on three methods of ASP. NET reading Excel files
- Import SQL Server database using ASP. NET Excel