已有56人关注
未处理NullReferenceexception错误
发表在C#图书答疑 2010-12-02
是否精华
版块置顶:
您好,
C#开发实战宝典 第30章进销存系统,做“往来对帐”测试时,双击“往来单位”列表下的某一行记录后,选择日期,单击“确定”出现“未处理NullReferenceexception”错误,


 if (i == currentAccountBook.dgvCurrentAccountList.RowCount - 1 && currentAccountBook.dgvCurrentAccountList[1, i].Value.ToString() == currentAccountBook.dgvCurrentAccountList[1 - 1, i].Value.ToString())
                {
                    currentAccountBook.dgvCurrentAccountList[4, i].Value = null;
                    currentAccountBook.dgvCurrentAccountList[6, i].Value = null;
                    break;
                }

代码为光盘的代码,请问如何解决?谢谢
分享到:
精彩评论 3
liangshui
学分:0 LV1
2010-12-02
沙发
读者你好:

    可以在“原有”if语句的外面增加一条判断语句,修改后的代码如下:
    if(currentAccountBook.dgvCurrentAccountList.Count() > 0)
    {
        if (i == currentAccountBook.dgvCurrentAccountList.RowCount - 1 && currentAccountBook.dgvCurrentAccountList[1, i].Value.ToString() == currentAccountBook.dgvCurrentAccountList[1 - 1, i].Value.ToString())
       {
          currentAccountBook.dgvCurrentAccountList[4, i].Value = null;
          currentAccountBook.dgvCurrentAccountList[6, i].Value = null;
          break;
       }
   }
link2011
学分:0 LV1
TA的每日心情
签到第一天
2022-05-09 11:13:49
2010-12-03
板凳
liangshui,你好,

在“原有”if语句的外面增加一条判断语句
if(currentAccountBook.dgvCurrentAccountList.Count() > 0)
也不能解决问题,
而且提示错误:
“System.Windows.Forms.DataGridView”不包含“Count”的定义,并且找不到可接受类型为“System.Windows.Forms.DataGridView”的第一个参数的扩展方法“Count”(是否缺少 using 指令或程序集引用?)
小科_mrkj
学分:43 LV2
2010-12-03
地板
读者朋友:
    您好,我们试了一下这个程序是好使的,你出现这个问题应该是日期格式(跟系统的日期格式有关)的问题,你在选择日期的代码处插入断点,然后跟踪一下那块的SQL语句,看一下SQL语句在SQL分析器中是否能够正常运行。
首页上一页 1 下一页尾页 3 条记录 1/1页
手机同步功能介绍
友情提示:以下图书配套资源能够实现手机同步功能
明日微信公众号
明日之星 明日之星编程特训营
客服热线(每日9:00-17:00)
400 675 1066
mingrisoft@mingrisoft.com
吉林省明日科技有限公司Copyright ©2007-2022,mingrisoft.com, All Rights Reserved长春市北湖科技开发区盛北大街3333号长春北湖科技园项目一期A10号楼四、五层
吉ICP备10002740号-2吉公网安备22010202000132经营性网站备案信息 营业执照