ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Create Family Tree Chart from Access Database using C# and VB.Net in ASP.Net<blockquote><cite>mfatih says:</cite> <div class="line number14 index13 alt1"><code class="csharp spaces">&nbsp;</code><code class="csharp plain">[WebMethod]</code></div> <div class="line number15 index14 alt2">&nbsp;</div> <div class="line number16 index15 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">protected</code> <code class="csharp keyword">void</code> <code class="csharp plain">Page_Load(</code><code class="csharp keyword">object</code> <code class="csharp plain">sender, EventArgs e)</code></div> <div class="line number17 index16 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">{</code></div> <div class="line number18 index17 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">OleDbConnection con = </code><code class="csharp keyword">new</code> <code class="csharp plain">OleDbConnection(</code><code class="csharp string">"Provider=Microsoft.ACE.OLEDB.12.0; DATA Source="</code> <code class="csharp plain">+ Server.MapPath(</code><code class="csharp string">"app_data/familytree.accdb"</code><code class="csharp plain">));</code></div> <div class="line number19 index18 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div> <div class="line number20 index19 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">public</code> <code class="csharp keyword">static</code> <code class="csharp plain">List&lt;</code><code class="csharp keyword">object</code><code class="csharp plain">&gt; GetChartData()</code></div> <div class="line number21 index20 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">{</code></div> <div class="line number22 index21 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code>&nbsp;</div> <div class="line number23 index22 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code>&nbsp;</div> <div class="line number24 index23 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">string</code> <code class="csharp plain">query = </code><code class="csharp string">"SELECT MemberId, Name, ParentId"</code><code class="csharp plain">;</code></div> <div class="line number25 index24 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">query += </code><code class="csharp string">" FROM FamilyHierarchy"</code><code class="csharp plain">;</code></div> <div class="line number26 index25 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">string</code> <code class="csharp plain">constr = ConfigurationManager.ConnectionStrings[</code><code class="csharp string">"constr"</code><code class="csharp plain">].ConnectionString;</code></div> <div class="line number27 index26 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">using</code> <code class="csharp plain">(OleDbConnection con = </code><code class="csharp keyword">new</code> <code class="csharp plain">OleDbConnection(constr))</code></div> <div class="line number28 index27 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">{</code></div> <div class="line number29 index28 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">using</code> <code class="csharp plain">(OleDbCommand cmd = </code><code class="csharp keyword">new</code> <code class="csharp plain">OleDbCommand(query))</code></div> <div class="line number30 index29 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">{</code></div> <div class="line number31 index30 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">List&lt;</code><code class="csharp keyword">object</code><code class="csharp plain">&gt; chartData = </code><code class="csharp keyword">new</code> <code class="csharp plain">List&lt;</code><code class="csharp keyword">object</code><code class="csharp plain">&gt;();</code></div> <div class="line number32 index31 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">cmd.CommandType = CommandType.Text;</code></div> <div class="line number33 index32 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">cmd.Connection = con;</code></div> <div class="line number34 index33 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">con.Open();</code></div> <div class="line number35 index34 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">using</code> <code class="csharp plain">(OleDbDataReader sdr = cmd.ExecuteReader())</code></div> <div class="line number36 index35 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">{</code></div> <div class="line number37 index36 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">while</code> <code class="csharp plain">(sdr.Read())</code></div> <div class="line number38 index37 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">{</code></div> <div class="line number39 index38 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">chartData.Add(</code><code class="csharp keyword">new</code> <code class="csharp keyword">object</code><code class="csharp plain">[]</code></div> <div class="line number40 index39 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">{</code></div> <div class="line number41 index40 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">sdr[</code><code class="csharp string">"MemberId"</code><code class="csharp plain">], sdr[</code><code class="csharp string">"Name"</code><code class="csharp plain">], sdr[</code><code class="csharp string">"ParentId"</code><code class="csharp plain">]</code></div> <div class="line number42 index41 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">});</code></div> <div class="line number43 index42 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div> <div class="line number44 index43 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div> <div class="line number45 index44 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">con.Close();</code></div> <div class="line number46 index45 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">return</code> <code class="csharp plain">chartData;</code></div> <div class="line number47 index46 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div> <div class="line number48 index47 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div> <div class="line number49 index48 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div> </blockquote> <p>&nbsp;replace above code with below and one more thing database table should contain records same as per the table structure used in sample</p> <pre class="brush: csharp">[WebMethod] public static List&lt;object&gt; GetChartData() { string query = &#34;SELECT MemberId, Name, ParentId&#34;; query += &#34; FROM FamilyHierarchy&#34;; using (OleDbConnection con = new OleDbConnection(&#34;Provider=Microsoft.ACE.OLEDB.12.0; DATA Source=&#34; + HttpContext.Current.Server.MapPath(&#34;app_data/familytree.accdb&#34;))) { using (OleDbCommand cmd = new OleDbCommand(query)) { List&lt;object&gt; chartData = new List&lt;object&gt;(); cmd.CommandType = CommandType.Text; cmd.Connection = con; con.Open(); using (OleDbDataReader sdr = cmd.ExecuteReader()) { while (sdr.Read()) { chartData.Add(new object[] { sdr[&#34;MemberId&#34;], sdr[&#34;Name&#34;], sdr[&#34;ParentId&#34;] }); } } con.Close(); return chartData; } } }</pre> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/145175/Create-Family-Tree-Chart-from-Access-Database-using-C-and-VBNet-in-ASPNet/https://www.aspforums.net:443/Threads/145175/Create-Family-Tree-Chart-from-Access-Database-using-C-and-VBNet-in-ASPNet/Wed, 24 May 2017 06:22:55 GMTCreate Family Tree Chart from Access Database using C# and VB.Net in ASP.Net<p>Thanks for your help. This codes works very well. Can we add husband or wife to a person changing the database?</p>https://www.aspforums.net:443/Threads/145175/Create-Family-Tree-Chart-from-Access-Database-using-C-and-VBNet-in-ASPNet/https://www.aspforums.net:443/Threads/145175/Create-Family-Tree-Chart-from-Access-Database-using-C-and-VBNet-in-ASPNet/Wed, 24 May 2017 06:48:02 GMTCreate Family Tree Chart from Access Database using C# and VB.Net in ASP.Net<p>You cannot ask multiple queries within a question. This is against forum rules and necessary to maintain clean forum.<br />It is requested. Mark Answer the replies when question is answered and ask a new question as a responsible member to help fellow programmers around the world.<br />Note: If you don't mark answers, people will loose interest in your questions.</p>https://www.aspforums.net:443/Threads/145175/Create-Family-Tree-Chart-from-Access-Database-using-C-and-VBNet-in-ASPNet/https://www.aspforums.net:443/Threads/145175/Create-Family-Tree-Chart-from-Access-Database-using-C-and-VBNet-in-ASPNet/Wed, 24 May 2017 06:58:02 GMTCreate Family Tree Chart from Access Database using C# and VB.Net in ASP.Net<p>Sorry for&nbsp;violating for your forum rules. I ddn't know this rule. I will respect your rules after this.</p>https://www.aspforums.net:443/Threads/145175/Create-Family-Tree-Chart-from-Access-Database-using-C-and-VBNet-in-ASPNet/https://www.aspforums.net:443/Threads/145175/Create-Family-Tree-Chart-from-Access-Database-using-C-and-VBNet-in-ASPNet/Wed, 24 May 2017 07:28:31 GMTCreate Family Tree Chart from Access Database using C# and VB.Net in ASP.NetInstead of saying thanks mark the reply or replies(if multiple) that helped as Answer.https://www.aspforums.net:443/Threads/145175/Create-Family-Tree-Chart-from-Access-Database-using-C-and-VBNet-in-ASPNet/https://www.aspforums.net:443/Threads/145175/Create-Family-Tree-Chart-from-Access-Database-using-C-and-VBNet-in-ASPNet/Wed, 24 May 2017 09:13:10 GMT