Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

Try this:
C#
//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();



All the best.
--Amit
 
Share this answer
 
Comments
daghune 4-Sep-12 0:41am    
excuse me for my questions,
what is DataBind() methods??
i have not it??
_Amy 4-Sep-12 0:46am    
This is the method which is used for binding the data in gridview. After calling this method only griview binds the data of datasource to it.
daghune 4-Sep-12 0:54am    
but i have not this method when typed:
dgvFinancial.
this method is not there
_Amy 4-Sep-12 1:05am    
Then you are using DataGrid. Sorry my mistake. Try binding with the query direct. It'll work.
_Amy 4-Sep-12 1:29am    
Accepted then undo?
Try This:
My be helpful for you.
C#
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 };
 
Share this answer
 
Comments
daghune 4-Sep-12 0:17am    
when i use query like your query compiler give me this Erroe:
Error 2 'Domain.Model.Financial' is a 'type' but is used like a 'variable'
prashant patil 4987 4-Sep-12 0:22am    
are you using DBML class. then add dbml classname before that Table name ?
use below code:
DataClassesDataContext obj = new DataClassesDataContext();
var query = from p in obj.tbl_PersonInfo
join f in obj.Financial on p.ID equals f.ID
select new { p.Id, p.Name, p.Family, f.debtValue, f.BestankarValue };
daghune 4-Sep-12 0:27am    
now problem is nothing show in gridview???
what should i do ?
please help me
prashant patil 4987 4-Sep-12 0:32am    
//Bind the gridview.
GridView1.DataSource = query;
GridView1.DataBind();
daghune 4-Sep-12 0:39am    
excuse me for my questions ,
what is DataBind() method
i have not it

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900