0

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

1
  • I would highly recommend getting LINQPad, where you can see the results and the actual query sent. It's a great "scratchpad" for working out Linq queries and free. linqpad.net Commented Mar 28, 2010 at 14:05

1 Answer 1

1

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();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.