下面的是Excel到dataset的函数,这个函数完后我用File.Delete();函数删除Excel文件报错
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Path + ";" + "Extended Properties=Excel 8.0;";
        OleDbConnection conn = new OleDbConnection(strConn);
        conn.Open();
        string strExcel = "";
        OleDbDataAdapter myCommand = null;
        //DataSet ds = new DataSet(); 
        strExcel = "select  *  from      [sheet1$]";
        myCommand = new OleDbDataAdapter(strExcel, strConn);        myCommand.Fill(ds, "table1");是不是上面的连接需要释放一下

解决方案 »

  1.   


    string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Path + ";" + "Extended Properties=Excel 8.0;"; 
            using(OleDbConnection conn = new OleDbConnection(strConn))
            {
            conn.Open(); 
            string strExcel = ""; 
            OleDbDataAdapter myCommand = null; 
            //DataSet ds = new DataSet(); 
            strExcel = "select  *  from      [sheet1$]"; 
            myCommand = new OleDbDataAdapter(strExcel, strConn);         myCommand.Fill(ds, "table1"); 
            }
            File.Delete();
      

  2.   

    File.close();这个函数怎么没有啊
      

  3.   

    using(OleDbConnection conn = new OleDbConnection(strConn))
    { conn.Open(); 
      ....
    }
    File.delete();
      

  4.   

    file.delete() 函数不用带参数吗?