zoukankan      html  css  js  c++  java
  • DataTable或DataSet之DBNULL判断

    DataTable或DataSet之DBNULL判断

    当数据源的数据是由SUM等操作产生的时候,非空判断除了判断是否COUNT外还需要判断DBNULL:

    if(dt.Rows.Count > 0)

    {

          if(DBNull.Value != dt.Rows[0]["Result"])

          {

               return Convert.ToInt32(dt.Rows[0]["Result"]);

          }

    }

    当然此时的情况可以选择先直接取出字段值,避开判断DBNULL:

    1

    2

    string str = dt.Rows[0]["Result"].ToString();

    return str.Length == 0 ? 0 : int.Parse(str);

    分类: C#

  • 相关阅读:
    HDU 1429
    HDU 1622
    HDU 3335
    HDU 4160
    HDU 1350
    HDU 5086
    HDU 1300
    HDU 3047
    HDU 3038
    HDU 5100
  • 原文地址:https://www.cnblogs.com/grj001/p/12224987.html
Copyright © 2011-2022 走看看