如果我的数据表为空值,则条件仍然为true ..告诉我我使用的条件是.... [英] if my datatable is null value still condition true..tell me which condition i use....

查看:151
本文介绍了如果我的数据表为空值,则条件仍然为true ..告诉我我使用的条件是....的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码

protected void Page_Load(object sender, EventArgs e)
   {
       if (!IsPostBack)
       {
           DataTable dtMax = gen.GetDataTable("SPSelectDCNMForMaxRecord");
           if (dtMax.Rows.Count > 0)
           {
               string strMaxNo = (Convert.ToInt32(dtMax.Rows[0]["maxRecord"].ToString()) + 1).ToString();
               lblDCNO.Text = strMaxNo;
           }
           else
           {
               lblDCNO.Text = "00000000001";
           }
           txtDate.Text =DateTime.Now.ToString();
           fillCustomerName();

           BindGrid();
       }

推荐答案

检查是否存在null:
Check for a null:
DataTable dtMax = gen.GetDataTable("SPSelectDCNMForMaxRecord");
if (dtMax != null && dtMax.Rows.Count > 0)

顺序很重要:如果您不先检查null,您将得到

The order is important: if you don''t check for null first, you will get an exception as you have been.



请在检查行计数之前检查null值.
if(dtMax!= null)

谢谢
Anil
Hi
please check null value before checking the row count.
if(dtMax != null)

Thanks
Anil


您可能还想检查行值是否不为空

You may also want to check the row value isn''t null

// checks the DataTable isn''t null, the maxRecord valus isn''t null and DataTable has rows

if (dtMax != null && dtMax.Rows.Count > 0 && dtMax.Rows[0]["maxRecord"] != null)


这篇关于如果我的数据表为空值,则条件仍然为true ..告诉我我使用的条件是....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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