question

WaithleyWilliams-7370 avatar image
0 Votes"
WaithleyWilliams-7370 asked JackJJun-MSFT commented

using (var csvReader = new CsvReader(reader)) is raising the error: CsvReader could not be found.

I have just started learning to use Visual Studio 2019 Community Edition and C#. I have run into an error that I don't know how to solve. The error is in this line:

using (var csvReader = new CsvReader(reader))

CS0246 -- CvsReader-- "The type of namespace name CvsReader could not be found. The code is as follows:

 using System;
 using System.IO;
 using System.Windows.Forms;
 using System.Linq;
 using LumenWorks.Framework.IO.Csv;
 using System.Globalization;
    
    
    
 namespace SMR_SCQ
    
 {
     public partial class Form3
     {
         public Form3(object records)
         {
             InitializeComponent();
                
             using (var reader = new StreamReader("C: /Users/sales/Desktop/SMR_SCQ_DB/SMR_SCQ/SMR_Databases"))
    
             using (var csvReader = new CsvReader(reader))
             {
                 records = csvReader.GetRecords<DataGridViewElement>().ToList();
             }
         }


Any help will be appreciated.

windows-forms
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.


CS0246 -- CvsReader-- "The type of namespace name CvsReader could not be found.

According to error message, maybe you wrote 'CvsReader' instead of 'CsvReader' in your real program.


0 Votes 0 ·

@WaithleyWilliams-7370, is any update? Please check if my answer works for you.

0 Votes 0 ·

1 Answer

JackJJun-MSFT avatar image
0 Votes"
JackJJun-MSFT answered

@WaithleyWilliams-7370, based on your code, I think you want to convert csv file to list.

You could try the following steps to solve the problem.

First, Please remove the reference related to LumenWorks.Framework.IO.Csv.

Second, Please install nuget-package CsvHelper.

Third, you could try the following code to get what you want.


 using CsvHelper;
 using System.Globalization;
 using System.IO;
 using System.Linq;
 using System.Windows.Forms;
    
 namespace Problem_for_csvreader
 {
     public partial class Form1 : Form
     {
         public Form1()
         {
             InitializeComponent();
    
             using (TextReader reader = new StreamReader("D:\\2.csv"))
    
             using (var csvReader = new CsvReader(reader,CultureInfo.CurrentCulture,false))
             {
                 var records = csvReader.GetRecords<Student>().ToList();
              
             }
         }
     }
    
    
     public class Student
     {
         public string Name { get; set; }
    
         public int Age { get; set; }
    
         public int ID { get; set; }
     }
 }

csv and result in winform:

144099-image.png




Hope this could help you.


If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



image.png (35.9 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.