使用linq在网格视图中绑定多个数据

使用linq在网格视图中绑定多个数据

本文介绍了使用linq在网格视图中绑定多个数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我有一个datagrid视图,该视图想显示来自两个表的多个数据,它们是tbl_PersonInfo和Financial,它们之间存在关系:
ID(PK)
姓名
家庭
............
FinancialPersonID(PK)(FK)
债务价值
Bestankarvalue
............
现在我想在gridView中显示Id,Name,Family,debtValue,BestankarValue
但是我什么都做不到!
哪个查询为True ????????
Gridview的Columns Generation和Columns属性应该是什么?????????
我是初学者,请帮我亲
感谢

hi all dev,
i have a datagrid view that want to show multiple data from two table that are tbl_PersonInfo and Financial , which they are in a relationship:
Id (PK)
Name
Family
............
FinancialPersonID (PK)(FK)
DebtValue
Bestankarvalue
............
Now i want to show Id,Name,Family,debtValue,BestankarValue in gridView
but i could not anything!!
which query is True????????
What should be Columns Generation of Gridview and Columns Property?????????
I m a Beginner,please help me pro
thanks

推荐答案

//Create the object of your context class.
DataContextClass1 ctx = new DataContextClass1();
//Join the both tables and select the columns required.
var query = from p1 in ctx.PersonInfo
            join f1 in ctx.Financial on p1.ID equals f1.ID
	    select new { p1.Id, p1.Name, p1.Family, f1.debtValue, f1.BestankarValue };
//Bind the gridview.
GridView1.DataSource = query;
GridView1.DataBind();




祝一切顺利.
--Amit




All the best.
--Amit


var query = from p in tbl_PersonInfo
            join f in Financial on p.ID equals f.ID
	    select new { p.Id, p.Name, p.Family, f.debtValue, f.BestankarValue };


这篇关于使用linq在网格视图中绑定多个数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 01:27