Call CBO.FillCollection "There is no constructor without parameters for this object." mistake

I'm trying to populate a collection from IDataReader that was returned by another method ... for some reason, it keeps throwing "No parameterless constructor defined for this object". error for this line:

List<string> names = CBO.FillCollection<string>(DataProvider.Instance().ExecuteReader("getNames", new SqlParameter("UserId", 1)));

I tried to separate the parameters so things get initialized separately until I had this:

List<string> names = CBO.FillCollection<string>(nameDataReader);

and I still got the error on one line.

Any ideas?

+3
source share
2 answers

. System.String, Activator.CreateInstance, .

. , :

var strings = new List<string>();
using(var reader = DataProvider.Instance().ExecuteReader("getNames", new SqlParameter("UserId", 1)))
{
    while(reader.Read()) 
        strings.Add(reader[0] as string);
}
+5

CBO.FillCollection , .

( ), , FillCollection, :

, SQL:

class StringRow { public string Name; } 

FillCollection, :

List<string> stringCollection = new List<string>();
foreach (StringRow row in CBO.FillCollection<StringRow>(DataProvider...)) 
{
    stringCollection.Add(row.Name);
}

, . , int, int "" ( SQL), , 0s.

, int? SQL [] .

+1

Source: https://habr.com/ru/post/1715094/


All Articles