DataGridView.Datasource = NULL;错误:未将对象引用设置到对象的实例 [英] DataGridView.Datasource = null; ERROR: Object reference not set to an instance of an object
本文介绍了DataGridView.Datasource = NULL;错误:未将对象引用设置到对象的实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我很困惑,为什么设置DataGridView控件为空的数据源,将导致一个对象引用不设置到对象的实例错误。在此先感谢
而(xmlReader.Read())
{
如果((xmlReader.NodeType == XmlNodeType.Element)及及(xmlReader.Name ==存款))
{
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;
}
}
解决方案
您应该使用这个,而不是设置数据源为空:
dgvDeposits.DataSource = typeof运算(存款);
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:
dgvDeposits.DataSource = typeof(Deposit);
Please check following question it might have an explanation for your exception.
这篇关于DataGridView.Datasource = NULL;错误:未将对象引用设置到对象的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文