有一csv文档,其中包含列num
num
15458
36548
2316584
zlpo165
1685现已将csv文档导入到DataTable,但num列中的第四行zlpo165读取不到值,其它全为数字的行都能读到,想请教是什么原因?

解决方案 »

  1.   

    paste your code, or set a breakpoint to debug your code to find out what happen on the line 4
      

  2.   

         //CVS文件
            public DataTable bb(string filepath, string filename)
            {
                string folderPath = filepath.Substring(0, filepath.LastIndexOf('\\') + 1);
                string cnstring=string.Format(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties='text;HDR=Yes;IMEX=1'", folderPath);  
                OleDbConnection cn = new OleDbConnection(cnstring);
                string aSQL = "select * from " + filename;
                cn.Open();
                OleDbDataAdapter da = new OleDbDataAdapter(aSQL, cn);
                DataSet ds = new DataSet();
                da.Fill(ds,"tb");
                cn.Close();
                DataTable dt = ds.table["tb"]
                return dt;
            }========================== 以上为读取csv数据至datatable ==========================
      

  3.   

    Sorry, I cannot find out any problem with your code.You can make more rows which is initialed by character, and see what happen to these rows.
      

  4.   

    你跟踪一下,我觉得读取csv应该没什么问题跟踪dt,看看里面有没有zlpo165
      

  5.   

    没这样写过,如果 csv 一般直接这样了:DataTable dt = new DataTable();
    dt.Columns.Add(...); 
    string[] lines = File.ReadAllLines();
    for (int i=0 i<= lines.Count()-1; i++)
    {
        DataRow dr = dt.NewRow();
        dr[".."] = lines[i];
        dt.Rows.Add(dr);
    }
      

  6.   

    把表结构发上来 可能是数据转换出了问题,怎么没有 bug处理,不做异常处理,异常信息就会无法获取到,要养成良好习惯,我这里有个从csv 文件导入数据导数据库的商业程序,需要的话可以把处理csv文件这部分发给你。
      

  7.   

    string filePath="http://221.130.10.100/osgplus/querys.jsp?begin=2010-06-12&end=2010-06-12";
    string fileName="yx_2010-06-12_2010-06-12";
    string path = Path.Combine(filePath, fileName + ".csv");
                string connString = @"Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" + filePath + ";Extensions=asc,csv,tab,txt;";
    这样写可以吗?
    路径是网络上的