c11ada
c11ada

Reputation: 4334

Linq-to-SQL question

im really new to linq-to-SQL so this may sound like a really dumb question, i have the following code

    var query = from p in DC.General
                where p.GeneralID == Int32.Parse(row.Cells[1].Text)
                select new
                {
                    p.Comment,
                };

how do i got about getting the result from this query to show in a text box ??

Upvotes: 0

Views: 61

Answers (1)

Prutswonder
Prutswonder

Reputation: 10074

That would be:

TextBox1.Text = query.Single().Comment;

You have to filter the first result from your query. To do that, you can use Single() if you know the query only returns one value. You could also use First(), if the results might contain more than one row.

Also, if it's only a single value, you could rewrite the code to:

var query = from p in DC.General
            where p.GeneralID == Int32.Parse(row.Cells[1].Text)
            select p.Comment;

TextBox1.Text = query.Single();

Upvotes: 1

Related Questions