Public ActionResult Upload (HttpPostedFileBase namefile)
{
//Determine if the file exists
if (NameFile = = null)
{
Return Content ("no Files");
}
//Get the name of the uploaded file, location
var fileName = DateTime.Now.ToString ("YYYYMMDDHHMMSS") + Namefile.FileName.Substring (Namefile.FileName.LastIndexOf ( ‘.‘));
//Perform upload
Namefile.saveas (Server.MapPath ("/fileexcel/" + fileName);
//Get file path, read data
String url = Server.MapPath ("/fileexcel/" + fileName);
//DT all the data in Excel that is read
DataTable dt = excelhelper.excelimport (URL);
Data in the Cycle DT
foreach (DataRow item in DT. Rows)
{
String str= "Insert Add statement";
}
Execute SQL statement
SqlCommand SqlCommand = new SqlCommand (str. ToString (), Getconn ());
//Perform data import
int q= SqlCommand. ExecuteNonQuery ();
if (q>0)
{
Return Content ("<script>alert (' upload completed, your upload was successful! '); location.href= '/fuli/fuliindex ' </script> ");
}
Else
{
Return Content ("<script>alert (' Failure! '); location.href= '/fuli/fuliindex ' </script> ");
}
}
C # npoi Data Bulk Import Database