Click here to Skip to main content
15,891,204 members
Home / Discussions / C#
   

C#

 
GeneralRe: Retrieve name of property incl. class and namespace Pin
Bernhard Hiller12-Sep-17 20:37
Bernhard Hiller12-Sep-17 20:37 
QuestionWhat is Delegets ? Why it is today's need in c# Pin
H M Mori10-Sep-17 23:06
professionalH M Mori10-Sep-17 23:06 
AnswerRe: What is Delegets ? Why it is today's need in c# Pin
Bohdan Stupak10-Sep-17 23:10
professionalBohdan Stupak10-Sep-17 23:10 
AnswerRe: What is Delegets ? Why it is today's need in c# Pin
OriginalGriff10-Sep-17 23:11
mveOriginalGriff10-Sep-17 23:11 
Questionhow to deal with exception in php Pin
H M Mori10-Sep-17 17:36
professionalH M Mori10-Sep-17 17:36 
AnswerRe: how to deal with exception in php Pin
Richard MacCutchan10-Sep-17 19:26
mveRichard MacCutchan10-Sep-17 19:26 
AnswerRe: how to deal with exception in php PinPopular
OriginalGriff10-Sep-17 19:54
mveOriginalGriff10-Sep-17 19:54 
QuestionHow do I make any method flexible? Pin
salm abdullsamad10-Sep-17 13:18
salm abdullsamad10-Sep-17 13:18 
Some time I make method for example the treenode in treeview some programmer write the code in four lines and it flexible me I write many lines and it is not flexible so if you have articles ,books help me to be proffessional make me call the method it self many times it will be nice.
this is my code:
C#
<pre>      public void FillTreeViewWith5(string Query1, string Query2, string Query3, string Query4,
            string Query5,string Query6,string Query7, DataSet Ds, TreeView tr, TreeNode tn1,
            TreeNode tn2, TreeNode tn3, TreeNode tn4, TreeNode tn5,TreeNode tn6,TreeNode tn7)
        {

            int z = 0;
            int r = 0;
            int res;
            string i1;
            string i2;
            string i3;
            string i4;
            string i5;
            string i6;
            tr.Nodes.Clear();
            SqlDataAdapter da1 = new SqlDataAdapter(Query1,con);
            da1.Fill(Ds, "d1");
            for (int i = 0; i < Ds.Tables["d1"].Rows.Count; i++)
            {
                i1 = Ds.Tables["d1"].Rows[i][0].ToString();
                string x1 = Ds.Tables["d1"].Rows[i][1].ToString();
                tn1 = new TreeNode(x1);
                SqlCommand cmd2 = new SqlCommand();
                cmd2.Connection = con;
                cmd2.CommandText = Query2;
                cmd2.Parameters.AddWithValue("@i1", i1);
                SqlDataAdapter da2 = new SqlDataAdapter(cmd2);
                da2.Fill(Ds, "d2");
                for (int j = 0; j < Ds.Tables["d2"].Rows.Count; j++)
                {
                    i2= Ds.Tables["d2"].Rows[j][0].ToString();
                    string x2 = Ds.Tables["d2"].Rows[j][1].ToString();
                    tn2 = new TreeNode(x2);
                    tn1.Nodes.Add(tn2);
                    SqlCommand cmd3 = new SqlCommand();
                    cmd3.Connection = con;
                    cmd3.CommandText = Query3;
                    cmd3.Parameters.AddWithValue("@i2", i2);
                    SqlDataAdapter da3 = new SqlDataAdapter(cmd3);
                    da3.Fill(Ds, "d3");
                    for (int b = 0; b < Ds.Tables["d3"].Rows.Count; b++)
                    {
                        i3 = Ds.Tables["d3"].Rows[b][0].ToString();
                        string x3 = Ds.Tables["d3"].Rows[b][1].ToString();
                        tn3 = new TreeNode(x3);
                        tn2.Nodes.Add(tn3);
                        SqlCommand cmd4 = new SqlCommand();
                        cmd4.Connection = con;
                        cmd4.CommandText = Query4;
                        cmd4.Parameters.AddWithValue("@i3", i3);
                        SqlDataAdapter da4 = new SqlDataAdapter(cmd4);
                        da4.Fill(Ds, "d4");
                        for (int c = 0; c < Ds.Tables["d4"].Rows.Count; c++)
                        {
                            i4 = Ds.Tables["d4"].Rows[c][0].ToString();
                            string x4 = Ds.Tables["d4"].Rows[c][1].ToString();
                            tn4 = new TreeNode(x4);
                            tn3.Nodes.Add(tn4);
                            SqlCommand cmd5 = new SqlCommand();
                            cmd5.Connection = con;
                            cmd5.CommandText = Query5;
                            cmd5.Parameters.AddWithValue("@i4", i4);
                            SqlDataAdapter da5 = new SqlDataAdapter(cmd5);
                            da5.Fill(Ds, "d5");
                           
                            for ( int m= 0; m <Ds.Tables["d5"].Rows.Count ; m++)
                            {

                                i5 = Ds.Tables["d5"].Rows[m][0].ToString();
                               string x5= Ds.Tables["d5"].Rows[m][1].ToString();
                               tn5 = new TreeNode(x5);
                               tn4.Nodes.Add(tn5);
                               SqlCommand cmd6 = new SqlCommand();
                               cmd6.CommandText = Query6;
                               cmd6.Connection = con;
                               cmd6.Parameters.AddWithValue( "@i5",i5);
                               SqlDataAdapter da6 = new SqlDataAdapter(cmd6);
                               da6.Fill(Ds, "d6");
                               
                                for (int p= 0; p < Ds.Tables["d6"].Rows.Count; p++)
                                {
                                    i6 = Ds.Tables["d6"].Rows[p][0].ToString();
                                    string x6 = Ds.Tables["d6"].Rows[p][1].ToString();
                                    tn6 = new TreeNode(x6);
                                    tn5.Nodes.Add(tn6);
                                    SqlCommand cmd7 = new SqlCommand();
                                    cmd7.CommandText = Query7;
                                    cmd7.Connection = con;
                                    cmd7.Parameters.AddWithValue("@i6", i6);
                                    SqlDataAdapter da7 = new SqlDataAdapter(cmd7);
                                    da7.Fill(Ds, "d7");
                                    res=Ds.Tables["d7"].Rows.Count;
                                    for (r = z; r < res; r++)
                                    {
                                        string i7 = Ds.Tables["d7"].Rows[r][0].ToString();
                                        string x7 = Ds.Tables["d7"].Rows[r][1].ToString();
                                        tn7 = new TreeNode(x7);
                                        tn6.Nodes.Add(tn7);
                                    }
                                    z = r;
                                    res = res + res;
                                    
                                }
                                


                               
                            

                            }
                           

                        }
                        
                    }

                    
                }
                
               
            }

            tr.Nodes.Add(tn1);
            tr.ExpandAll();

        }

the proffessional programmer code:
C#
<pre>private void AddTreeNode(TreeNode parentNode, DataTable table, int parentId)
{
    //filter rows, get all rows that have specified parent ID
    var filteredRows = table.AsEnumerable().Where(r => Convert.ToInt32(r["parent_id"]) == parentId).ToList();
    //go through all those rows
    foreach(DataRow row in filteredRows)
    {
        //make treeview
        TreeNode node = new TreeNode(row["Re_nm"].ToString());
        //add it to parent (first time that will be treeview)
        if (parentNode == null)
            tr.Nodes.Add(node);
        else
            parentNode.Nodes.Add(node);

        //now call same method second time, now with new node and parent id 151111
        AddTreeNode(node, table, Convert.ToInt32(row["Re_id"]));
        //next time, this will be called with parent id 151112 etc.
    }
}

AnswerRe: How do I make any method flexible? Pin
Mycroft Holmes10-Sep-17 13:31
professionalMycroft Holmes10-Sep-17 13:31 
Questionis a c# totally based on OOPS concept? Pin
Hardevsinh Mori8-Sep-17 18:07
professionalHardevsinh Mori8-Sep-17 18:07 
AnswerRe: is a c# totally based on OOPS concept? Pin
Richard MacCutchan8-Sep-17 19:23
mveRichard MacCutchan8-Sep-17 19:23 
AnswerRe: is a c# totally based on OOPS concept? Pin
Dave Kreskowiak9-Sep-17 7:32
mveDave Kreskowiak9-Sep-17 7:32 
JokeRe: is a c# totally based on OOPS concept? Pin
Mycroft Holmes9-Sep-17 14:19
professionalMycroft Holmes9-Sep-17 14:19 
GeneralRe: is a c# totally based on OOPS concept? Pin
Dave Kreskowiak9-Sep-17 14:22
mveDave Kreskowiak9-Sep-17 14:22 
QuestionHow Can I Add Membership To My Program Pin
istemihan8-Sep-17 11:59
istemihan8-Sep-17 11:59 
AnswerRe: How Can I Add Membership To My Program Pin
Richard MacCutchan8-Sep-17 19:21
mveRichard MacCutchan8-Sep-17 19:21 
Answerjoin and sum in linqu Pin
Member 109061148-Sep-17 5:28
Member 109061148-Sep-17 5:28 
QuestionC# and XAML bindings - Need Help with events and dependent Drop Down Lists Pin
Member 133487177-Sep-17 4:45
Member 133487177-Sep-17 4:45 
AnswerRe: C# and XAML bindings - Need Help with events and dependent Drop Down Lists Pin
Mycroft Holmes7-Sep-17 13:20
professionalMycroft Holmes7-Sep-17 13:20 
Questionget more than one string in the checkedlistbox using an array C # Pin
Member 133640086-Sep-17 6:56
Member 133640086-Sep-17 6:56 
SuggestionRe: pegar mais de uma string no checkedlistbox usando um arrayList C# Pin
Richard Deeming6-Sep-17 7:07
mveRichard Deeming6-Sep-17 7:07 
QuestionError on xml.Response Pin
Bootzilla335-Sep-17 21:10
Bootzilla335-Sep-17 21:10 
AnswerRe: Error on xml.Response Pin
OriginalGriff5-Sep-17 21:19
mveOriginalGriff5-Sep-17 21:19 
AnswerRe: Error on xml.Response Pin
Pete O'Hanlon6-Sep-17 0:30
mvePete O'Hanlon6-Sep-17 0:30 
SuggestionRe: Error on xml.Response Pin
Richard Deeming6-Sep-17 6:00
mveRichard Deeming6-Sep-17 6:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.