"System.Data.EnumerableRowCollection`1[System.Object]" question

  • Thread starter Thread starter Paolo
  • Start date Start date
P

Paolo

I'm trying to populate a rich text box with the results of a query, thus:

private void button1_Click(object sender, EventArgs e)
{
var query
from trans in dataSet.Transaction
select new
{
trans.T_Date,
trans.T_PayeeId,
trans.T_Category,
trans.T_SubCategory,
trans.T_PayMethod,
trans.T_Amount
};
foreach (var item in query)
{
richtxbxAnalysis.Text = query.Cast<object>().ToString();
}
}

My text box is showing:

"System.Data.EnumerableRowCollection`1[System.Object]" and nothing else.

I'd appreciate advice on how to display the data requested in the query.
 
i think you wanted code this :

private void button1_Click(object sender, EventArgs e)
{
var query =
from trans in dataSet.Transaction
select new
{
trans.T_Date,
trans.T_PayeeId,
trans.T_Category,
trans.T_SubCategory,
trans.T_PayMethod,
trans.T_Amount
};
foreach (var item in query)
{
richtxbxAnalysis.Text = item.ToString();
}
}
 
richtxbxAnalysis.Text = query.Cast<object>().ToString();
My text box is showing:

"System.Data.EnumerableRowCollection`1[System.Object]" and nothing else.

You're casting the query to an object and then calling ToString(). Object's
implementation of ToString() simply returns the class name. In other words,
it's doing exactly what you told it to do.

Why did you think you needed to cast to object?
 
Jeremy: thanks. That gave me a data row, but, it appears, only the final row
in the dataset. I thought a simple 'select', as shown, would return all items
in the dataset (which is what I want).
 
Jeff: most probably because I'm learning and still don't have sufficient
comprehension of LINQ/Enumerable/Anonymous Types! What I coded at least gave
me an entry in the text box. Everything else I tried gave an exception about
not being able to cast a TransactionRow to String.

Jeff Johnson said:
richtxbxAnalysis.Text = query.Cast<object>().ToString();
My text box is showing:

"System.Data.EnumerableRowCollection`1[System.Object]" and nothing else.

You're casting the query to an object and then calling ToString(). Object's
implementation of ToString() simply returns the class name. In other words,
it's doing exactly what you told it to do.

Why did you think you needed to cast to object?
 
OK, this solves that problem:

foreach (var item in query)
{
richtxbxAnalysis.AppendText(item.ToString());
richtxbxAnalysis.AppendText("\n");
}
 
Back
Top