• excel导入数据库的代码


    excel导入数据库的代码   
                 try
                {
                
                    OleDbDataReader dr1 = OAConfig1.MyReaderexcel("/source_file.xls","00",3,"SELECT * FROM [空间$]");
                   if(dr1.Read())
                   {
                      do
                      {
                         string ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath("/targetdb.mdb")+";Jet OLEDB:Database Password=;"; 
                         OleDbConnection Connother = new OleDbConnection(ConnString);
                            if (Connother.State == ConnectionState.Closed)Connother.Open();
                      OleDbCommand  MyComm=new OleDbCommand("insert into 空间 (A,B,C,D,E,F,G)  values ('"+dr1[0].ToString()+"','"+dr1[1].ToString()+"','"+dr1[2].ToString()+"','"+dr1[3].ToString()+"','"+dr1[4].ToString()+"','"+dr1[5].ToString()+"','"+dr1[6].ToString()+"')", Connother);   
                         MyComm.ExecuteNonQuery();
                         MyComm.Dispose();
                      Connother.Close();
                      }while(dr1.Read());
                      
                   }
                   else
                   {
                     Response.Write("此Excel表是空的");
                   }
                    dr1.Close();
                }
                finally
                {
                
                OAConfig1.CloseConnexcel();
                
                }
                  Response.Write("此Excel导入ACCESS成功");
             
          }

  • 相关阅读:
    js给redio设置哪一个被选中
    问候struts2升级的新版本2.5
    图片上传与显示时候的路径问题
    Json,String,Map之间的转换
    springboot之web
    关于struts2中出现的漏洞,如何测试解决
    Table-valued functions and Scalar-valued functions in SQL Server
    Using system view: sys.sysprocesses to check SqlServer's block and deadlock
    利用sys.sysprocesses检查SqlServer的阻塞和死锁
    SQLSERVER加密解密函数(非对称密钥 证书加密 对称密钥)
  • 原文地址:https://www.cnblogs.com/pretty/p/1276626.html
Copyright © 2020-2023  润新知