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

返回的值为空?
为何像如下的代码写返回值绑定到Total里。看不到绑定内容呢?
private   void   Page_Load(object   sender,   System.EventArgs   e)
if(IsPostBack)
{
id   =   Convert.ToInt32(ddlName.SelectedValue.ToString());

Total.Text   =   myVisit.GetTotal(id);

}
 
public   string   GetTotal(int   id)
{
string   sqlTotal   =   "Select   Sum(Count_Visit)   as   Total   from   Visit_Day   where   [userid]   =   "   +   id.ToString();
try
{
string   count   =   ExecuteSql4String(sqlTotal);
return   count;
}
catch
{
return   null;
}
}

以下是ExecuteSql4String()方法:
protected   string   ExecuteSql4String(string   strSQL)
{
//SqlConnection   myCn   =   new   SqlConnection(strConn);
SqlCommand   myCmd   =   new   SqlCommand(strSQL,myCn);
try
{
myCn.Open();
object   r   =   myCmd.ExecuteScalar();
if(Object.Equals(r,null))
{
throw   new   Exception( "value   unavailable! ");
}
else
{
return   (string)r;
}
}
catch(System.Data.SqlClient.SqlException   e)
{
throw   new   Exception(e.Message);
}
finally
{
myCmd.Dispose();
myCn.Close();
}
}

谢谢!

------解决方案--------------------
string sqlTotal = "Select Sum(Count_Visit) as Total from Visit_Day where [userid] = " + id.ToString(); === 看这条记录查询出来会不会有值.
------解决方案--------------------
用事件探查器跟踪一下看看.