日期:2014-05-18 浏览次数:21488 次
string outTxt = ""; 
            Object obj= new CBD.BLL.sroot().GetModel(pid);
if(obj!=null)
{
outTxt =obj.title; 
}
            return outTxt;
------解决方案--------------------
string 不用new。
可用以下写法:
protected string getPidTitle(int pid)  
       {  
           string outTxt = "";  
           outTxt = CBD.BLL.sroot().GetModel(pid).title.ToString().Trim();  
           return outTxt;  
       }  
------解决方案--------------------
outTxt = new CBD.BLL.sroot().GetModel(pid).title;  
跟
outTxt = (new CBD.BLL.sroot()).GetModel(pid).title;
语法上是一样的,自己在VS中一打就知道了
因为楼主获取的对像GetModel(pid)这个方式,不一定能够返回对像,如果返回null,如果是null就没有对像.title属性了,所以出错了,解决办法就是参考我前面的回答