日期:2014-05-17  浏览次数:20799 次

请教下大家为空的时候怎么处理
类型有  string   int   bool   这个几个比较有代表吧

我模型里面是这么做的
public DateTime? Approvedate { get; set; }
public String Picture { get; set; }
public Boolean? Planstatus { get; set; }

然后读到datagridview 中  有些直接在数据库中是空的null
点击datagridview之后  对每个单元格进行读取  再在下面text控件显示出来 为了方便我做了个类型转换的类
里面的方法为:(请大家帮我看下下面行不行)
 public static int? convertint(string intvalue)
        {
            int? typeint=null;
            if (intvalue == null || intvalue =="")
            {
                typeint = null;
            }
            else
            {
                typeint = Convert.ToInt32(intvalue);
            }
            return typeint;
        }
        public static DateTime? convertdatetime(string datetimevalue)
        {
            DateTime? typedatetime = null;
            if (datetimevalue == null || datetimevalue =="")
            {
                typedatetime = null;
            }
            else
            {
                typedatetime = Convert.ToDateTime(datetimevalue);
            }
            return typedatetime;
        }
        public static bool? convertbool(string boolvalue)
        {
            bool? typebool = null;
            if (boolvalue == null || boolvalue == "")
            {
                typebool = null;
            }
            else
           &