开发者

Linq-to-SQL question

开发者 https://www.devze.com 2022-12-24 04:40 出处:网络
im really new to linq-to-SQL so this may sound like a really dumb question, i have the following code

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,
                };

h开发者_JAVA技巧ow 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();
0

精彩评论

暂无评论...
验证码 换一张
取 消