We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Org chart based on data in SQL table

Thread ID:





72986 Apr 15,2008 02:40 AM UTC Apr 20,2008 06:04 PM UTC WinForms 1
Tags: Diagram
Heath Dillon
Asked On April 15, 2008 02:40 AM UTC


I have a SQL table that contains some data related to our company structure. Basiclly its a table that holds role names as well as what role reports to what role.

From that we can build a org chart.

Can easily display this using the diagram component ?

Is the component smart enough to draw itself based on the sql data(suh as just binding the component to a dataset) or do I need to draw the diagram in code myself ?

Administrator [Syncfusion]
Replied On April 20, 2008 06:04 PM UTC

Hi Heath,

Thank you for using Syncfusion products.

Display OrgChart based on data from SQL.

Please refer the OrgLayout sample in Syncfusion\EssentialStudio\\Windows\Diagram.Windows\Samples\2.0\Demo Diagrams\OrgLayout\ demonstrates how to draw the diagram layout by retrieving the informations from an Access database. Referring to the sample's MainForm class InitializeDiagramFromDatabase(..) and ReadEmployeeDataFromDatabase(..) methods demonstrate about how to read data from an Access database.

Essential Diagram also supports reading data from a SQL database. Using System.Data.SqlClient.SqlConnection instead of the OleDbConnection will let the user to read the data from the sql database.

Here is a sample code snippet to read data from a Sql Database:


private Hashtable ReadEmployeeDataFromSql()

Hashtable htemployees = new Hashtable();

string connectionstring = "workstation id=SYNCCHN;packet size=4096;user id=sa;password=pwd;data source=SYNCCHN;persist security info=False;initial catalog=tempdb";
// Query to select all records from the Org.mbd database
string orgdbselectquery = "SELECT EmployeeID, Name, ManagerID FROM TempEmployees";
System.Data.SqlClient.SqlConnection sqlConnection = new SqlConnection(connectionstring);
SqlCommand orgdbcommand = new SqlCommand(orgdbselectquery, sqlConnection);
// Create a connection to the datasource
// Execute the query command to build the data reader
SqlDataReader orgdbreader = orgdbcommand.ExecuteReader();
// Extract employee data from the reader
object[] employeedata = new object[3];
int count = orgdbreader.GetValues(employeedata);

// Create an Employee instance to represent each employee
Employee emply = new Employee();
emply.EmployeeID = employeedata[0].ToString();
emply.EmployeeName = (string)employeedata[1];
if(count == 3)
emply.ManagerID = employeedata[2].ToString();
htemployees.Add(emply.EmployeeID, emply);
// Close the reader
// Close the connection

return htemployees;

Essential diagram does not have support for directly binding the diagram component to a database. We need to read the data from the DataReader and create instanace for Employee object in the Organization.

Please let me know if this helps you.



This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon