如果数据表为null,则为tick条件 [英] Tick condition if datatable null C#

查看:83
本文介绍了如果数据表为null,则为tick条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我正在使用tick函数显示从数据库到数据表的更新数据。现在,问题是我当前的数据库是null,数据将由用户稍后插入。当我运行该程序时,它显示错误对象引用未设置为实例,现在如何确保tick函数运行而不抛出错误?



我尝试了什么:



Hi guys, i'm using tick function to show updated data from database to datatable. Now, the problem is my current database is null, data will be insert by user later. When i'm run the program it's showing error "object reference not set to an instance", now how can i make sure the tick function is running without throwing the error?

What I have tried:

private void timer_Tick (object sender, EventArgs e)
{
   this.tbl_StoredDataTableAdapter.Fill(this.gpdbDataSet.tbl_StoredData);
}





请帮帮我。谢谢!



Please help me. Thank you!

推荐答案

简单:检查空值。

Simple: check for nulls.
private void timer_Tick (object sender, EventArgs e)
   {
   if (tbl_StoredDataTableAdapter != null && gpdbDataSet != null && gpdbDataSet.tbl_StoredData != null)
      {
      this.tbl_StoredDataTableAdapter.Fill(this.gpdbDataSet.tbl_StoredData);
      }
   }


这篇关于如果数据表为null,则为tick条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆