The release number of this article has been CHS308454
For Microsoft Visual Basic .NET versions of this article, see
CHS308057.
This task content
summary
Steps to create an example
Summary This article demonstrates how to display parent information and sub-information filled with relationship datasets.
DataGrid control. In the father
When you move in the data set, you can click
The plus ( ) on the left side of DataGrid view the relevant sub-record.
Back to top
Steps to create an example
Open Microsoft Visual Studio .NET, create a new Visual C # Windows application project. Use the toolbox to add a Button control to the default form and a DataGrid control. In the Properties window, change the Text property of the button to LOAD. Double-click LOAD to add an event handler. Add the following code to the top of the Code window: use system.data.sqlclient; add the following code to the Button1_Click event handler: SqlConnection Con = New SqlConnection ("Server = HaroldO2; UID = sa;"
"pwd = password1; database = northwind");
SqlDataAdapter Dacust = New SqlDataAdapter ("Select * from Customers Where Customerid Like 'a%'", CON);
Sqldataadapter Daorders = New SqldataAdapter ("Select * from Orders Where Customerid Like 'a%'", CON;
DataSet DS = New Dataset ();
Dacust.Fill (DS, "Cust");
Daorders.Fill (DS, "ORDERS");
// Creates the RelationShip.
DS.RELATIONS.ADD ("CustORD", DS.Tables ["Cust"]. Columns ["Customerid"],
Ds.Tables ["Orders"]. Column ["Customerid"]);
DataGrid1.datasource = DS;
DataGrid1.datamember = "CUST"; modify the SQLConnection string to point to a valid Microsoft SQL Server database. Press the F5 key to compile and run the application. Please note that the initial grid is empty. Click LOAD to populate the grid. Click the plus sign ( ) to display the link to the subcord. In this example, a sub-relation is displayed. Click this relationship to display subcord. In the upper right corner of the grid, click the back arrow to return to the parent record.
Back to top
The information in this article applies to:
Microsoft Visual C # .NET (2002)
Recent Updated: 2002-2-24 (1.0) Keyword Kbhowto KbhowTomaster KB308454