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.
Unfortunately, activation email could not send to your email. Please try again.

Org chart based on data in SQL table

Thread ID:

Created:

Updated:

Platform:

Replies:

72986 Apr 14,2008 10:40 PM Apr 20,2008 02:04 PM Windows Forms 1
loading
Tags: Diagram
Heath Dillon
Asked On April 14, 2008 10:40 PM

Hi,

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 02:04 PM

Hi Heath,

Thank you for using Syncfusion products.

Display OrgChart based on data from SQL.

Please refer the OrgLayout sample in Syncfusion\EssentialStudio\6.2.0.40\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:

[C#]


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
sqlConnection.Open();
// Execute the query command to build the data reader
SqlDataReader orgdbreader = orgdbcommand.ExecuteReader();
// Extract employee data from the reader
while(orgdbreader.Read())
{
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
orgdbreader.Close();
// Close the connection
orgdbcommand.Connection.Close();

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.

Regards,
Jaya



CONFIRMATION

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.

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.

;