Relations

  • Thread starter George Chatzimanolis
  • Start date
G

George Chatzimanolis

I have a question to ask.

I have one Dataset with two Datatables (Customers, Orders) and a
DataRelation between these tables. I would like to ask If it is possible to
create a datagrid in a window form (VB.NET for example) which shows the
table Order but instead of showing Customer_ID , to show Customer_Name.


Original Table
---------------
Order_ID | Customer_ID | Order_Date


I would like
------------

Order_ID | Customer_Name (from Relationship) | Order_Date.



Is this possible?

Best Regards

George
 
V

Vikas Aggarwal

Yes its possible just assign the specified dataset in the datagrids
datasource property.
 
G

George Chatzimanolis

Thanks for your answer but the thing is that I want to have only one
datagrid without the + symbol.
 
A

Andrew Conrad

Add a column with an expression that refers to the parent column:

DataSet ds = new DataSet();
ds.Tables.Add("Customer");
ds.Tables.Add("Orders");

DataTable cust = ds.Tables["Customer"];
cust.Columns.Add("Customer_ID", typeof(int));
cust.Columns.Add("Customer_Name", typeof(string));

DataTable orders = ds.Tables["Orders"];
orders.Columns.Add("Order_ID", typeof(int));
orders.Columns.Add("Customer_ID", typeof(int));

DataRelation rel = new DataRelation("CustOrder",
cust.Columns["Customer_ID"], orders.Columns["Customer_ID"]);
ds.Relations.Add(rel);
orders.Columns.Add("Customer_Name", typeof(string),
"Parent.Customer_Name");

Andrew Conrad
Microsoft Corp
http://blogs.msdn.com/aconrad/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top