Treeview error

R

Reetu

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();
 
P

Patrick.O.Ige

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 said:
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();
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top