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>");

        }
            } 

  • 相关阅读:
    Spring之InstantiationAwareBeanPostProcessor接口介绍
    Spring之BeanPostProcessor(后置处理器)介绍
    JVM中垃圾收集算法总结
    JVM中对象的回收过程
    zookeeper实现动态感知服务器上下线
    Spring事务的传播行为
    java工厂模式
    Spring加载流程源码分析03【refresh】
    Redis客户端操作之Jedis
    微服务设计的四个原则
  • 原文地址:https://www.cnblogs.com/liuyi-li/p/6340786.html
Copyright © 2011-2022 走看看