日期:2014-05-20  浏览次数:20467 次

怎么判断返回的是System.String.Empty
public static string ValidateDataRow_S(DataRow row, string colname)
  {
  if (row[colname] != DBNull.Value)
  return row[colname].ToString();
  else
  return System.String.Empty;
  }
怎么判断返回的是System.String.Empty


比如说类admin中的password为空值,不是null值
我admin.password=="" 或者 admin.password==null 或者 admin.password.length==0都不行,不知道怎么回事


------解决方案--------------------
string.IsNullOrEmpty()
------解决方案--------------------
如果是空值,admin.password == string.Empty 结果为true
如果为null asmin.password == null 结果为 true
如果在DataGrid中, == DBNull.Value 结果为 true

还有一种可能,看上去为空,实际上是很多空白字符的组合,这种情况发生在数据类型为char的列中
所以上面的任何比较代码都会为false
所以,需要使用下面的代码判断
admin.password.Trim() == string.Empty;

------解决方案--------------------
admin.password.Trim().length=0
------解决方案--------------------
if(!string.IsNullOrEmpty(ref))
{
//不為空時
}
else
{
//為空時
}
------解决方案--------------------
string.IsNullOrEmpty()
这个.
------解决方案--------------------
你在MSDN里查一下 DbNull
------解决方案--------------------
Try:

if (row[colname] == DBNull.Value || row[colname].ToString().Trim()=="")
{
return System.String.Empty; 
}
else
{
return row[colname].ToString().Trim(); 
}
------解决方案--------------------
建议把if (row[colname] != DBNull.Value)
改成 if (!string.IsNullOrEmpty(row[colname].toString())&&row[colname].toString().Trim()!="0")

------解决方案--------------------
探讨
都不行,因为我的admin.password是调用了下面这个函数返回的
public static string ValidateDataRow_S(DataRow row, string colname)
{
if (row[colname] != DBNull.Value)
return row[colname].ToString();
else
return System.String.Empty;
}


this._password = GetSafeData.ValidateDataRow_S(dr, "password");

------解决方案--------------------
Please view at: http://resumessys8.ps.duoduo.cn/diary/item/ff8080811feeda1c011ff4b5fbab0342.html
------解决方案--------------------
if(!String.IsNullOrEmpty("值")
{
//....
}
------解决方案--------------------
C# code

        string str = System.String.Empty;
        if (string.IsNullOrEmpty(str))
            Response.Write("System.String.Empty");
        else
            Response.Write("error");

------解决方案--------------------
探讨
C# code

string str = System.String.Empty;
if (string.IsNullOrEmpty(str))
Response.Write("System.String.Empty");
else
Response.Write("error");


Empty 你不会判断,你返回null 不可以么 ? 就认准Empty 了 ?
都告诉你怎么判断了,你自己不去试

哪位 版主大仙啊 ~  这也推荐

------解决方案--------------------