IsNull数据库 [英] IsNull database

查看:96
本文介绍了IsNull数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好:

我想给label.text表单数据库赋值
但是如果该值为null,我想为label.text
指定特定的值.
像这样的简短代码:

Hi guys:

I want to assign value to label.text form database
but if the value is null i want to assign specific value to the label.text

in brief code like that:

if (UserProfileInformation.Tables[0].Rows[0].IsNull("UserFirstName"))
        {
            UserFirstNameData.Text = "not found";
        }
        else
        {
            UserFirstNameData.Text = UserProfileInformation.Tables[0].Rows[0]["UserFirstName"].ToString();
        }



代码很好用,
但是它有点长,我在页面上有很多标签,
所以我想要可能的简洁代码

谢谢........



that code work good ,
but it somewhat long and i have many labels on the page ,
so i want gentle and simple code if it could possible

thanks........

推荐答案

没什么困难

No too difficult

private static void CheckForNull(object obj, Label label, string text)
{
  string labelText = text;
  if(obj != DbNull.Value)
  {
     labelText = obj.ToString();
  }

  label.Text = labelText;  
}

CheckForNull(UserProfileInformation.Tables[0].Rows[0]["UserFirstName"],
UserFirstNameData, "not found");


这篇关于IsNull数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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