By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,650 Members | 753 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,650 IT Pros & Developers. It's quick & easy.

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

P: n/a
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.
Nov 21 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"Paolo" <Pa***@discussions.microsoft.comwrote in message
news:B3**********************************@microsof t.com...
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?
Nov 21 '08 #2

P: n/a
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).

"Jérémy Jeanson" wrote:
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érémy JEANSON
MCP
http://jeremy.blogdns.net
Nov 21 '08 #3

P: n/a
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" wrote:
"Paolo" <Pa***@discussions.microsoft.comwrote in message
news:B3**********************************@microsof t.com...
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?
Nov 21 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.