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. Image for the cookie policy date
close icon

Diagram

Hi,

I downloaded the eval version and trying to create a expander according to the infomration in my database. I have couple questions.

1)The sample i see is reading from XML. How can i read the data directly from SQL? is it possible and what is the table format if it is possible?

2) where can i find the sample code to create the diagram with the default symbol? what method is called to create symbol and connector?


Thanks,

Eva

1 Reply

RR Ramya R Syncfusion Team March 28, 2007 09:23 AM UTC

Hi Eva,

Thanks for your interest in Essential Diagram.

With regard to your first query, Yes, it is possible to access the data from SQL Database and create nodes.
Kindly take a look at the code snippet below and add it to the Expander sample(Syncfusion\Essential Studio\4.4.0.51\Web\diagram.web\Samples\2.0\Expander) and call the InitializeDiagramFromDatabase() method under the PageLoad event and comment the call for InitializeDiagramFromXMLData() method under the PageLoad event.

protected void InitializeDiagramFromDatabase()
{

// Read data from the SQL database and populate a Hashtable using the employee ID as the key
Hashtable htemployees = this.ReadEmployeeDataFromDatabase();

// Create a manager-employee nested list with top-level employees forming the root nodes
ArrayList sortedlist = this.GetSortedEmployeesList(htemployees);

foreach (ExpanderSymbol expsymbol in sortedlist)
this.CalculateSubNodeCount(expsymbol);

// Create diagram symbol nodes for each employee and initialize the diagram
this.CreateOrgDiagramFromList(sortedlist);

htemployees.Clear();
sortedlist.Clear();
}

protected Hashtable ReadEmployeeDataFromDatabase()
{
Hashtable htemployees = new Hashtable();
string connString = "user id=;pwd=;data source=;persist security info=False;initial catalog=Employees";
SqlConnection sqlConn = new SqlConnection(connString);
string selectquery = "SELECT EmployeeID, Name, ManagerID FROM Employees";
SqlCommand sqlCommand = new SqlCommand(selectquery, sqlConn);
sqlConn.Open();
SqlDataReader sqlReader = sqlCommand.ExecuteReader();
// Extract employee data from the reader
while (sqlReader.Read())
{
object[] employeedata = new object[3];
int count = sqlReader.GetValues(employeedata);

// Create an Employee instance to represent each employee
ExpanderSymbol emply = new ExpanderSymbol();
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
sqlReader.Close();
// Close the connection
sqlCommand.Connection.Close();

return htemployees;
}


I have attached the AccessFormat of the Database which I have used in the above code snippet. Kindly import it to SQL Database Collection using the EnterpriseManager before adding the above code snippet to the Expander sample.

Now the run the Expander sample, the output appears with the nodes created using the data in database.

Let me know whether this helps you.


Regarding your second query, could please provide me with some more information with regard to the condition that you have mentioned here, so that it would help us in meeting your requirement exactly.


Thanks & Regards,
Ramya.


Loader.
Live Chat Icon For mobile
Up arrow icon