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


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.
 
Ad

Advertisements

J

Jérémy Jeanson

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();
}
}
 
J

Jeff Johnson

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?
 
P

Paolo

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).
 
P

Paolo

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?
 
P

Paolo

OK, this solves that problem:

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

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top