hi all i want to ask about retrieve data to textbox using LINQ to SQL c# i'm using visual studio 2013 Ultimate Edition

i have a *.dbml file and some textboxt..

this is the code :

DataClasses1DataContext db = new DataClasses1DataContext();
        var query = from c in db.Library
                    select c.Book;

and i want to retrieve data to :

**textboxt**<hr>
title.text;<br>
name.text;<br>
bookcode.text;<hr>

NB : using C# (LINQ to SQL) winform Visual Studio 2013

有帮助吗?

解决方案

var query = from c in db.Library select c.Book;

Above code will return multiple record of books. So you have to loop over "query"

for eg

foreach (var q in query)

        {
            Response.Write(q.ToString()); // "q" will have your database record
        }

其他提示

Looking at the code that you have posted, it'll return you a result set of all the books present in the Library. So, first you need to select a particular book based on some condition in your query. Or, you can also select one book by FirstOrDefault()(does not make sense to just do this, just saying).

After you get one book, you can display the values in textboxes like so

txtTitle.Text = query.Title;
txtName.Text = query.Name; //and so on

If you want to display all the books values then you need to iterate through the result set and display them accordingly.

Let me know if you further help on this.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top