I’m confused as to why setting the datasource of a datagridview control to null, would cause an “object reference not set to an instance of an object” error. Thanks in advance
while (xmlReader.Read())
{
if ((xmlReader.NodeType == XmlNodeType.Element) && (xmlReader.Name == "deposits"))
{
oDeposit.DepAmt = Convert.ToDouble(xmlReader.GetAttribute("depamount"));
oDeposit.DepDate = Convert.ToDateTime(xmlReader.GetAttribute("depdate"));
oDeposit.DepositId = Convert.ToInt32(xmlReader.GetAttribute("depid"));
oCustomer.addDeposits(oDeposit);
**dgvDeposits.DataSource = null;**
dgvDeposits.DataSource = oCustomer.Deposits;
}
}
You should use this instead of setting DataSource to null:
Please check following question it might have an explanation for your exception.