zoukankan      html  css  js  c++  java
  • 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成功");
             
          }

  • 相关阅读:
    面向对象-类
    模块04
    总结
    昨天的新的解决方法
    感冒了~ vs中py和vb实现一个小算法
    vs2015社区版不支持installshield
    网站被黑了
    2018/11/18(python)
    2018/11/14
    2018/11/12(python)
  • 原文地址:https://www.cnblogs.com/pretty/p/1276626.html
Copyright © 2011-2022 走看看