Treeview error

Discussion in 'ASP .Net Web Controls' started by Reetu, Oct 26, 2004.

  1. Reetu

    Reetu Guest

    Hi All,

    I need to populate the treeview dynamically from the the
    tables specie,serie and product. I am not able to get rid
    of the following error " System.ArgumentException: These
    columns don't currently have unique values."

    I am refering to one of the msdn examples and have done
    the same as specified in the example.

    It would be very kind if someone can tell me whats wrong
    in the code below.


    Thanks,
    -Reetu

    string query1 = "SELECT Specie_Id, Specie_Name FROM
    Specie";

    string query2 = "SELECT
    Specie_Id ,Serie_Id,Serie_Name " +
    "FROM serie where
    Specie_Id in (SELECT Specie_Id FROM Specie)";

    string query3= "SELECT top 10
    Serie_Id,Product_Name,Product_Id " +
    "FROM Product where
    serie_Id in " +
    "(SELECT Serie_Id " +
    "FROM serie where
    Specie_Id in (SELECT Specie_Id FROM Specie))";

    //SqlConnection objConn = new
    SqlConnection
    ("server=SALVIA;database=GSI_OFFLINE_ED;uid=sa;pwd=xoutsql2
    ");
    SqlConnection objConn = new
    SqlConnection
    ("server=Kompassom;database=GSI_OFFLINE_ED;uid=sa;pwd=xouts
    ql2");
    SqlDataAdapter daSpecies = new
    SqlDataAdapter(query1,objConn);
    DataSet objDS = new DataSet();
    daSpecies.Fill(objDS,"dtSpecie");

    SqlDataAdapter daSeries = new
    SqlDataAdapter(query2,objConn);
    daSeries.Fill(objDS,"dtSerie");

    SqlDataAdapter daProducts = new
    SqlDataAdapter(query3,objConn);
    daProducts.Fill
    (objDS, "dtProduct");

    objConn.Close();

    objDS.Relations.Add
    ("SpecieToSerie",
    objDS.Tables
    ["dtSerie"].Columns["Specie_Id"],
    objDS.Tables
    ["dtSpecie"].Columns["Specie_Id"],false);

    objDS.Relations.Add("SerieToProd",
    objDS.Tables
    ["dtSerie"].Columns["Serie_Id"],
    objDS.Tables
    ["dtProduct"].Columns["Serie_Id"],false);

    TreeNode
    nodeSpecie,nodeSerie,nodeProd;

    foreach(DataRow rowSpecie in
    objDS.Tables["dtSpecie"].Rows)
    {
    nodeSpecie = new TreeNode
    ();
    nodeSpecie.Text = rowSpecie
    ["Specie_Name"].ToString();
    nodeSpecie.ID = rowSpecie
    ["Specie_Id"].ToString();
    TreeView1.Nodes.Add
    (nodeSpecie);

    foreach(DataRow rowSerie
    in rowSpecie.GetChildRows("SpecieToSerie"))
    {
    nodeSerie = new
    TreeNode();
    nodeSerie.Text =
    rowSerie["Serie_Name"].ToString();
    nodeSerie.ID =
    rowSerie["Serie_Id"].ToString();

    nodeSpecie.Nodes.Add(nodeSerie);

    foreach(DataRow
    rowProd in rowSerie.GetChildRows("SerieToProd"))
    {
    nodeProd =
    new TreeNode();

    nodeProd.Text = rowProd["Product_Name"].ToString();

    nodeProd.ID = rowProd["Product_Id"].ToString();

    nodeSerie.Nodes.Add(nodeProd);
    }
    }

    }

    objDS.Dispose();
    daSpecies.Dispose();
    daSeries.Dispose();
    daProducts.Dispose();
    objConn.Close();
    objConn.Dispose();
     
    Reetu, Oct 26, 2004
    #1
    1. Advertising

  2. Hi Reetu,
    Are u getting the Data from different tables?
    Well i can post u a full code but all my data was from one table
    Or post how ur Tables look like!


    "Reetu" wrote:

    > Hi All,
    >
    > I need to populate the treeview dynamically from the the
    > tables specie,serie and product. I am not able to get rid
    > of the following error " System.ArgumentException: These
    > columns don't currently have unique values."
    >
    > I am refering to one of the msdn examples and have done
    > the same as specified in the example.
    >
    > It would be very kind if someone can tell me whats wrong
    > in the code below.
    >
    >
    > Thanks,
    > -Reetu
    >
    > string query1 = "SELECT Specie_Id, Specie_Name FROM
    > Specie";
    >
    > string query2 = "SELECT
    > Specie_Id ,Serie_Id,Serie_Name " +
    > "FROM serie where
    > Specie_Id in (SELECT Specie_Id FROM Specie)";
    >
    > string query3= "SELECT top 10
    > Serie_Id,Product_Name,Product_Id " +
    > "FROM Product where
    > serie_Id in " +
    > "(SELECT Serie_Id " +
    > "FROM serie where
    > Specie_Id in (SELECT Specie_Id FROM Specie))";
    >
    > //SqlConnection objConn = new
    > SqlConnection
    > ("server=SALVIA;database=GSI_OFFLINE_ED;uid=sa;pwd=xoutsql2
    > ");
    > SqlConnection objConn = new
    > SqlConnection
    > ("server=Kompassom;database=GSI_OFFLINE_ED;uid=sa;pwd=xouts
    > ql2");
    > SqlDataAdapter daSpecies = new
    > SqlDataAdapter(query1,objConn);
    > DataSet objDS = new DataSet();
    > daSpecies.Fill(objDS,"dtSpecie");
    >
    > SqlDataAdapter daSeries = new
    > SqlDataAdapter(query2,objConn);
    > daSeries.Fill(objDS,"dtSerie");
    >
    > SqlDataAdapter daProducts = new
    > SqlDataAdapter(query3,objConn);
    > daProducts.Fill
    > (objDS, "dtProduct");
    >
    > objConn.Close();
    >
    > objDS.Relations.Add
    > ("SpecieToSerie",
    > objDS.Tables
    > ["dtSerie"].Columns["Specie_Id"],
    > objDS.Tables
    > ["dtSpecie"].Columns["Specie_Id"],false);
    >
    > objDS.Relations.Add("SerieToProd",
    > objDS.Tables
    > ["dtSerie"].Columns["Serie_Id"],
    > objDS.Tables
    > ["dtProduct"].Columns["Serie_Id"],false);
    >
    > TreeNode
    > nodeSpecie,nodeSerie,nodeProd;
    >
    > foreach(DataRow rowSpecie in
    > objDS.Tables["dtSpecie"].Rows)
    > {
    > nodeSpecie = new TreeNode
    > ();
    > nodeSpecie.Text = rowSpecie
    > ["Specie_Name"].ToString();
    > nodeSpecie.ID = rowSpecie
    > ["Specie_Id"].ToString();
    > TreeView1.Nodes.Add
    > (nodeSpecie);
    >
    > foreach(DataRow rowSerie
    > in rowSpecie.GetChildRows("SpecieToSerie"))
    > {
    > nodeSerie = new
    > TreeNode();
    > nodeSerie.Text =
    > rowSerie["Serie_Name"].ToString();
    > nodeSerie.ID =
    > rowSerie["Serie_Id"].ToString();
    >
    > nodeSpecie.Nodes.Add(nodeSerie);
    >
    > foreach(DataRow
    > rowProd in rowSerie.GetChildRows("SerieToProd"))
    > {
    > nodeProd =
    > new TreeNode();
    >
    > nodeProd.Text = rowProd["Product_Name"].ToString();
    >
    > nodeProd.ID = rowProd["Product_Id"].ToString();
    >
    > nodeSerie.Nodes.Add(nodeProd);
    > }
    > }
    >
    > }
    >
    > objDS.Dispose();
    > daSpecies.Dispose();
    > daSeries.Dispose();
    > daProducts.Dispose();
    > objConn.Close();
    > objConn.Dispose();
    >
    >
    >
     
    Patrick.O.Ige, Oct 28, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?VHltYm93?=
    Replies:
    2
    Views:
    24,608
    =?Utf-8?B?VHltYm93?=
    Jan 10, 2006
  2. abargaddon
    Replies:
    0
    Views:
    1,097
    abargaddon
    Jan 17, 2008
  3. Per Salmi

    TreeView not rendering nodes? Cacheing of a TreeView

    Per Salmi, Oct 15, 2003, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    502
    Steve Drake
    Oct 15, 2003
  4. Ionutz
    Replies:
    2
    Views:
    555
    Ionutz
    Oct 23, 2005
  5. stepkurt

    Microsoft Treeview vs System Treeview

    stepkurt, Aug 29, 2007, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    410
    Teemu Keiski
    Sep 2, 2007
Loading...

Share This Page