zoukankan      html  css  js  c++  java
  • C# NPOI的数据批量导入数据库

    public ActionResult Upload(HttpPostedFileBase Namefile)
            {
                //判断文件是否存在
                if (Namefile == null)
                {
                    return Content("没有文件");
                }
                //获取上传文件的名称,位置
                var fileName = DateTime.Now.ToString("yyyyMMddhhmmss") + Namefile.FileName.Substring(Namefile.FileName.LastIndexOf('.'));
                //执行上传
                Namefile.SaveAs(Server.MapPath("/FileExcel/" + fileName));
                //获取文件路径,读取数据
                string url = Server.MapPath("/FileExcel/" + fileName);
                //dt为读取到的所有Excel里的数据
                DataTable dt = ExcelHelper.ExcelImport(url);

        //循环dt里的数据
                foreach (DataRow item in dt.Rows)
                {

          string str="insert添加语句"; 

                }

         //执行SQL语句
                SqlCommand sqlcommand = new SqlCommand(str.ToString(), GetConn());
                //执行数据导入
               int q=  sqlcommand.ExecuteNonQuery();

        if(q>0)

        {

          return Content("<script>alert('上传已完成,您上传成功!');location.href='/FuLi/FuLiIndex'</script>");

        }

        else

        {

          return Content("<script>alert('失败!');location.href='/FuLi/FuLiIndex'</script>");

        }
            } 

  • 相关阅读:
    图论-最短路
    windows对拍及其应用
    RMQ与st表
    树状数组
    二分和三分题
    [转载]图论500题
    浏览器请求背后的网络数据传输过程
    百度ocr文字识别接口使用
    Mysql启动报错解决方案:Failed to open log (file './mysql-bin.000901', errno 2)
    Mac环境下nginx https配置
  • 原文地址:https://www.cnblogs.com/liuyi-li/p/6340786.html
Copyright © 2011-2022 走看看