Ask coding questions

← Back to all posts
C# - How to use DataTable on System.Data Assembly?
MO5 (4)

I have an error when using the System.Data namespace, I'm trying to read a CSV file into a DataTable object.

using System;
using System.Data;

class MainClass {
  public static void Main (string[] args) {
    DataTable exampleData = new DataTable();
    exampleData = ConvertToDataTable("./example.csv", 2);

    foreach (DataRow dataRow in exampleData.Rows)
      foreach (var item in dataRow.ItemArray)

  public DataTable ConvertToDataTable (string filePath, int numberOfColumns)
  { ... }

main.cs(2,14): error CS0234: The type or namespace name Data' >does not exist in the namespaceSystem'. Are you missing >`System.Data' assembly reference?