error: key already exists
i am working in c# with infragistics
In c# windows applicaion, I will be passing data from textbox..such that
for example:i haev 3 texboxes labeled
name:
age:
salary:...
Now name is the parent and age and salary r the child..so if i pass data in
the appropriate textbox..It should be added in the ultrawintree......such that
name(parent) should show up on the root node of the tree. and age and
salary(child) should show up under the root node.
I did this as follows..
//ultrawintree
private Infragistics.Win.UltraWinTree.UltraTree ultraTree1;
//form load
private void Form1_Load(object sender, System.EventArgs e)
{
DataSet dataSet = new DataSet();
//read the schema
dataSet.ReadXmlSchema("..\\..\\Menu.xsd");//menu.xsd contains name, age and salary
dataSet.WriteXml("..\\..\\resultdata.xml",XmlWriteMode.WriteSchema);
}
//buttton click
private void button1_Click(object sender, System.EventArgs e)
{
DataSet dataSet = new DataSet();
// Read the existing xml
dataSet.ReadXml("..\\..\\resultdata.xml");
//name textbox--string type
string strName = txtName.Text;
//age text box--int type
string strage = txtAge.Text;
int intAge;
if (!strAge.Equals(string.Empty)) // check to make sure the user entered something
intAge = Convert.ToInt32(strAge);
//Salary textbox--int type
string strSalary = txtSalary.Text;
int intSalary;
if (!strSalary.Equals(string.Empty)) // check to make sure the user entered something
intSalary = Convert.ToInt32(strSalary);
//create a new row
DataRow newrow;
newrow = dataSet.Tables[0].NewRow();
// add new row.
newrow["Name"] = strName;
newrow["Age"] = strAge;
newrow["Salary"] = strSalary;
//add parent node in ultrawintree
Infragistics.Win.UltraWinTree.UltraTreeNode anode = new Infragistics.Win.UltraWinTree.UltraTreeNode();
//add parent node
anode.Text = txtName.Text;
//add child nodes
anode.Nodes.Add(txtAge.Text);
anode.Nodes.Add(txtSalary.Text);
anode.Expanded = true;
ultraTree1.Nodes.Add(anode);
//add the row to the dataset
dataSet.Tables[0].Rows.Add(newrow);
//write the data to a xml file
dataSet.WriteXml("..\\..\\resultdata.xml", XmlWriteMode.WriteSchema);
dataSet.AcceptChanges();
MessageBox.Show("Saved");
}
so now when i run this program, as it reads a xml schema and creates a xml file.. now when i clicked the button, it checks for teh xml file and each textbox
is binded to teh xml elements..so that the data which is passed in the xml file willbe added in teh xml..
now for example i gave john,22,1800 for name,age and salary respectively
it is added in the xml..no when i give rex, 22,1700 again and when i cick the button..it shows that key already exists..key:22..
so please help met o add this..wht should i do to overcome this error
dhol

