Abolfazl

Abolfazl

  • NA
  • 184
  • 81.3k

how to load database in a listview with linq to sql?

Mar 23 2014 9:23 AM
hi
i want to load a table of database to a listview.i know how to create columns for listview and how to add items in them,
but i don't know how to add data from database with linq.
i write this code:
 
databaseDataContext db = new databaseDataContext();
var query = db.accountinfos;
for (int i = 0; i < query.Count();i++ )
{
var field = db.accountinfos.Where(c => c.id == i+1).Single();
ListViewItem item = new ListViewItem(field.bankname.ToString());
item.SubItems.Add(field.accountnumber.ToString());
}
 
please help me. 
thanks 
 
 
 

Answers (1)