简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM