I am building a table on the fly in C#. This table may or may not contain certain columns. I need a row made up of the distinct values from a raw table. (i.e. Agent Name, Manager Name etc).
I use:
var DistinctTable = SourceTable.DefaultView.ToTable(true, "AName", "MName");
and it works fine, but I need this to work with something like
string Groupby = "";
if (AName != "")
{
Groupby = AName;
}
if (MName != "")
{
Groupby = Groupby + MName;
}
var DistinctTable = SourceTable.DefaultView.ToTable(true, Groupby);
I'm dumbing this down a bit for simplicity but the premise is there. I have tried options of adding in quotes, adding in comma's etc. Nothing works the best I have done is to receive the error
There is no column '"AName","MName"' in table (x)
is this possible?