Skip to content
← Back to Community
C# - How to use DataTable on System.Data Assembly?
Profile icon
MO5

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) { Console.WriteLine(item); } } } 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?

Voters
Profile icon
JoshuaCobb
Profile icon
BarSn
Profile icon
ThatKidWhoCodes
Profile icon
suriradhika
Profile icon
JustinGrant
Profile icon
MO5