The text of this article is not in this database — only its details are. Read it on the old site: Displaying single table database hierarchy with DataSet and DataRelations
2 Comments
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment.

eliza sahooPosted Jun 7, 2010, 7:42 AM
During the development of a page you may need to populate a number of controls from DB. In that case you have to write a number of functions to populate different controls. In this tip I am going to show you a way to do all these operations in a single function. Step 1: - Write the different queries for getting the data from the DB for different controls in a single string variable by separating them with semicolon. Ex - //Create the SQL query. string selectQueryForControlPopulation = "SELECT COL1,COL2,... FROM TABLE_NAME1 WHERE CONDITION; SELECT COL1,COL2,..FROM TABLE_NAME2 WHERE CONDITION; ......"; Step 2: - Create the DataAdapter, DataSet object. Execute the query and fill the DataSet object. Ex - //Create the Connection object. OleDbConnection oConnection = newOleDbConnection(ConfigurationSettings.AppSettings["SQLConnectionString"]); //Create the Command object. OleDbCommand oCommand = new OleDbCommand(selectQueryForControlPopulation , oConnection ); //Create the DataAdapter object and set its property. OleDbDataAdapter oAdapter = new OleDbDataAdapter(); oAdapter .SelectCommand = oCommandPopulateOrganizations; // Create a DataSet object. DataSet oDataSet = new DataSet(); //Filling the DataSet object. oAdapter .Fill(oDataSet); (**) The DataSet object contain the result of different queries as different tables. We can access those table to fill our controls. http://www.mindfiresolutions.com/Populate-multiple-controls-from-DB-in-a-single-function-using-a-single-DataSet-831.php
eric fritzPosted Feb 28, 2008, 3:36 AM
Hi Jigar, Do you know why I receive the following error: System.ArgumentNullException: 'column' argument cannot be null. on the Datarelation line: Dim relation As New DataRelation("ParentChild", result.Tables("Employee").Columns("EmployeeID"), result.Tables("Employee").Columns("ReportsTo"), True) Thanks