我不知道这里的strConn语句有没有问题,我也不清楚到底怎么写!请那位高手指点指点!只要到conn.Open();就会出现异常,我估计是连接字符串有问题!我等着完成这个任务!
       string strConn = @"Provider=Microsoft.Jet.OLEDB.4.0;Driver={Microsoft.Text.Driver (*.csv)}; Data Source = " + Path + ";" + "Extensions Properties=csv;FMT=TabDelimited;";
        OleDbConnection conn = new OleDbConnection(strConn);
        conn.Open();
        DataTable dt = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
        string strExcel = "";
        OleDbDataAdapter myCommand = null;
        if (Table == "shareit")
            strExcel = "SELECT * FROM [" + dt.Rows[0]["TABLE_NAME"].ToString() + "] WHERE EMAIL<>null";
        else
            if (Table == "paypal")
                strExcel = "SELECT * FROM [" + dt.Rows[0]["TABLE_NAME"].ToString() + "] where [ From Email Address] <> null";
        DataSet ds = new DataSet();
        myCommand = new OleDbDataAdapter(strExcel, strConn);
        myCommand.Fill(ds, Table);
        conn.Close();
        return ds;

解决方案 »

  1.   

    试试这个
    public DataSet GetDataSetFromCSV(string filePath, string fileName)
      {
       string strConn = @"Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=";
           strConn += filePath;                //filePath, For example: C:\
           strConn += ";Extensions=asc,csv,tab,txt;" ;
       OdbcConnection objConn = new OdbcConnection(strConn);
       DataSet dsCSV = new DataSet();
       try
       {
        string strSql = "select * from " + fileName;   //fileName, For example: 1.csv
        OdbcDataAdapter odbcCSVDataAdapter = new OdbcDataAdapter(strSql, objConn);
        odbcCSVDataAdapter.Fill(dsCSV);
        return dsCSV;
       }
       catch(Exception ex)
       {
        throw ex;
       }  
      }
      

  2.   

    还是有点问题,在执行Fill的时候,放生异常,说表的路径不对,是不是还要在odbcCSVDataAdapter.Fill(dsCSV);后面加上一个路径??
      

  3.   

    到这里看看吧
    http://www.cnblogs.com/chenyunfan/articles/599482.html
      

  4.   

    说路径不对是因为你后面的
    string strSql = "select * from " + fileName;这里的fileName中包含有路径(只能是文件名)
    而上面的strConn += filePath的filePath只能用路径,关于这一点myminimouse(坚决不用baidu)已说得很清楚了