a,b,c
1,2,3
8,8,9
9,7,4
请来来段代码读取abc.csv文件
好比说查询a列等于8的c列的值
谢谢了

解决方案 »

  1.   

    用一个System.Web.UI.HtmlControls.HtmlInputFile去handle文件选取。
    以下是button click event中的code,用来执行当文件选取了之后读取文件的内容。System.Web.HttpPostedFile input = Request.Files[0];if (input != null && input.ContentLength != 0)
    {
    string path = input.FileName.ToString();
    System.IO.StreamReader reader = new System.IO.StreamReader(path);

    reader.Peek();
    while (reader.Peek() > 0)
    {
    string str = reader.ReadLine();
    string[] split = str.Split(',');
    if (split[0] != "" && split[1] != "")
    {
    System.Data.DataSet ds = new DataSet();
    System.Data.DataRow dr = ds.Tables[0].NewRow();
    dr[0] = split[0];
    dr[1] = split[1];
    ds.Tables[0].Rows.Add(dr);
    }
    }
    }
    把csv文件中的内容读到dataset里面。你应该看得懂。
      

  2.   

    可以先用xsl来格式成一个xml文件,然后按照操作xml文件的方法操作数据
      

  3.   

    刚刚做过,直接当表来读
    SELECT *
    INTO theImportTable
    FROM
    OPENROWSET('MSDASQL',
    'Driver={Microsoft Text Driver (*.txt; *.csv)};DEFAULTDIR=D:\;Extensions=CSV;',
    'SELECT * FROM CSVFile.csv')
      

  4.   

    OPENROWSET('MSDASQL',
    'Driver={Microsoft Text Driver (*.txt; *.csv)};DEFAULTDIR=D:\;Extensions=CSV;',
    'SELECT * FROM CSVFile.csv')
    好复杂哦
      

  5.   

    简单的说就是将csv文件当作一个数据库来操作,使用ole驱动
      

  6.   

    还有没有更简单的 直接操作csv文档 通过逗号和回车符判断
      

  7.   

    a,b,c
    1,2,3
    8,8,9
    9,7,4
    请来来段代码读取abc.csv文件
    好比说查询a列等于8的c列的值
    谢谢了
      

  8.   

    int  intColCount = 0;
    DataTable mydt = new DataTable("myTableName");DataColumn mydc;
    DataRow mydr;string strpath = "";
    string strline;
    string [] aryline;            System.IO.StreamReader mysr = new System.IO.StreamReader(strpath);while((strline = mysr.ReadLine()) != null)
    {               
        aryline = strline.Split(new char[]{'|'});    intColCount = aryline.Length;
        for (int i = 0; i < aryline.Length; i++)
        {
            mydc = new DataColumn(aryline[i]);
            mydt.Columns.Add(mydc);
        }                        mydr = mydt.NewRow();
        for (int i = 0; i < intColCount; i++)
        {
            mydr[i] = aryline[i];        
        }
        mydt.Rows.Add(mydr);
    }
      

  9.   

    ok i have a question that what's the CSV file ? how to use it?