Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hOW TO display a data of id and its sub ids in treeview
this is my code in c# and ms access data base it not displaying all of it

C#
private void button2_Click(object sender, EventArgs e)
{
    l:

        try
        {

            con = new OleDbConnection(cs);
            con.Open();
            //Sales.ReferenceID = Customer.CustomerID and
            cmd = new OleDbCommand("SELECT * from Sales where   CustomerID='" + textBox22.Text + "' order by  CustomerID ASC ", con);
            OleDbDataAdapter myDA = new OleDbDataAdapter(cmd);
            DataTable rdr = new DataTable();
            myDA.Fill(rdr);

            for (int i = 0; i < rdr.Rows.Count; i++)
            {
                TreeNode node = new TreeNode(rdr.Rows[i]["CustomerNameSales"].ToString());
                node.Nodes.Add(rdr.Rows[i]["ReferenceID"].ToString());
                node.Nodes.Add(rdr.Rows[i]["CustomerID"].ToString());
                node.Nodes.Add(rdr.Rows[i]["Rank"].ToString());
                node.Nodes.Add(rdr.Rows[i]["checkcol"].ToString());
                treeView1.Nodes.Add(node);
            }


            con.Close();

        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }

        try
        {

            con = new OleDbConnection(cs);
            con.Open();
            String ct102000 = "SELECT CustomerID from Sales where ReferenceID = '" + textBox22.Text + "'";
            cmd = new OleDbCommand(ct102000, con);
            rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);


            if ((rdr.Read() == true))
            {

                textBox21.Text = (rdr["CustomerID"].ToString());
                textBox22.Text = textBox21.Text;

                if (textBox22.Text != null)
                {
                    goto l;

                }

                goto l;
            }

            con.Close();
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }



}

give me a solution
[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 24-Jan-14 21:27pm
v2

1 solution

Under normal circumstances, I would look at that code and try to work out what is wrong.
But in this case, I'm not going to, because the code is clearly so poorly written, and fixing it's problem-as-seen-by-you is just the least of it's problems.

No.
Throw that lot in the bin. Sit down and think about what you are trying to do and start again from scratch. And this time, forget that the keyword goto ever existed. Do not write code like this again:
C#
if ((rdr.Read() == true))
{

    textBox21.Text = (rdr["CustomerID"].ToString());
    textBox22.Text = textBox21.Text;

    if (textBox22.Text != null)
    {
        goto l;

    }

    goto l;
}
Ever. In fact, do not use a label, or goto for at least five years. By then, you should understand when it is and isn't appropriate...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900