Null reference exception in Linq

getmoney18

New Member
I am .net beginner. I have gone through many sites before asking here. I am getting error -- "Object reference not set to an instance of an object." .This error comes usually when there are null values in any control but in my case Every control has some text in them, then why this error coming? here is my xml file\[code\]cmbProduct --> combobox txtNewBrand --> textBoxtxtUpdateQuantity --> textBoxtxtUpdatePrice --> textBox\[/code\]I tried the below code:onButtonClick \[code\]var newElement = new XElement("items", new XElement("productname", cmbProduct.Text), new XElement("brandname", txtNewBrand.Text), new XElement("quantity", txtUpdateQuantity.Text), new XElement("price", txtUpdatePrice.Text)); /*ERROR*/ doc.Element("stock").Add(newElement); doc.Save(xpath); MessageBox.Show("updated successfully");\[/code\]Please Help
Thanks in Advance.
 
Back
Top