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