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成功");
         
      }

原文地址:https://www.cnblogs.com/pretty/p/1276626.html