Import Excel and notepad data to the database

Source: Internet
Author: User

 

Import mobile phone numbers to the database in batches. Idea: First upload the file to be imported to the project, then read each row of data in the file and insert it into the database. After the operation, delete the uploaded file. Example: Excel: notepad: front-end code:
<Div = id = runat = visible => <fieldset> <p> <label> </label> <asp: fileUpload ID = runat =/> <= runat = ErrorMessage = ControlToValidate => </asp: requiredFieldValidator> </p> <label> file example </label>  </p> </fieldset> <div => </div> <div => </div> <div style => <asp: button ID = runat = Text = CssClass ==/> & nbsp; & <input = type = value = onclick =/> </div> <div = id = runat = visible => <fieldset> <p> <label> </label> <asp: fileUpload ID = runat =/> <= runat = ErrorMessage => </asp: requiredFieldValidator> </p> <label> file example </label>  </p> </fieldset> <div => </div> <div => </div> <div style => <asp: button ID = runat = Text = CssClass ==/> & nbsp; & <input = type = value = onclick =/> </div>


Background code

             btnExcel_Click( backStr= UploadFile(FileUpload1, , (backStr ==                   Js.ShowSureMsgBox(.Page,  (backStr == .Page,  url = backStr;                     DataTable dt = (dt.Rows.Count >  ( i = ; i < dt.Rows.Count; i++                     {
                         
                           phoneNum= dt.Rows[i][].ToString();                       }   .Page, btnNotepad_Click( backStr = UploadFile(FileUpload2, , (backStr == .Page, (backStr == .Page, url = backStr; DataTable dt = (dt.Rows.Count > ( i = ; i < dt.Rows.Count; i++
phoneNum= dt.Rows[i][].ToString(); }
} .Page, UploadFile(FileUpload FileUploadName, varfilename, (FileUploadName.HasFile) fileExtension = System.IO.Path.GetExtension(FileUploadName.FileName).ToLower(); (type == (fileExtension != && fileExtension != (type == (fileExtension != fpath = System.Web.HttpContext.Current.Server.MapPath( + varfilename + ); (!Directory.Exists(fpath)) time = DateTime.Now.ToString(); picturename = time + newFilePath = fpath + picturename; newFilePath; ; DataTable ExcelToDataSet( strCon = + filename + = = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, [] { , , , [] strTableNames = ( k = ; k < dtSheetName.Rows.Count; k++= dtSheetName.Rows[k][= = strExcel = + strTableNames[] + = DataTable ReadTXT(= = , System.Type.GetType( sLine = (sLine != = (sLine != && !sLine.Equals(=] =

 

 

 

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.