如何在csv文件

时间:2016-04-16 07:33:18

标签: c#-4.0

我已经上传了一个csv文件,并且还从csv file.now创建了一个数据表。我想从data-table的每一列中找到不同的值。这将是代码。 我试过这个代码,但有错误显示对象不是ADODB.what是ADODB,我该如何删除此错误

   public static DataTable GetDataTabletFromCSVFile(string csv_file_path)
{
 DataTable csvData = new DataTable();
try
 {
     using (TextFieldParser csvReader = new TextFieldParser(csv_file_path))
     {
        csvReader.SetDelimiters(new string[] { "," });
        csvReader.HasFieldsEnclosedInQuotes = true;
        //read column names
        string[] colFields = csvReader.ReadFields();
        foreach (string column in colFields)
        {
           DataColumn datecolumn = new DataColumn(column);
           datecolumn.AllowDBNull = true;
           csvData.Columns.Add(datecolumn);
        }
        while (!csvReader.EndOfData)
        {
           string[] fieldData = csvReader.ReadFields();
           //Making empty value as null
           for (int i = 0; i < fieldData.Length; i++)
           {
              if (fieldData[i] == "")
              {
                 fieldData[i] = null;
              }
           }
           csvData.Rows.Add(fieldData);
        }
  foreach (DataColumn col in csvdata.Columns)
            {

                foreach (DataRow ro in csvdata.Rows)
                {
                    textBox1.Text = "" + ro[col];

                }

            }
     }
  }
  catch (Exception ex)
  {
     MessageBox.Show(ex.Message);
  }

}

0 个答案:

没有答案