为何像如下的代码写返回值绑定到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();
}
}谢谢!
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();
}
}谢谢!
解决方案 »
- 谁有支付宝的例子?
- asp.net连接数据库遇到的问题
- 像新闻发布的网站,当阅读某个新闻的时候,在左下方会出现1个相关新闻的列表 ,这个关系是怎么确定的?
- 大家有谁作过娱乐网站,都来交流一下噢
- |zyciis| 如何查看Context.Cache.Insert添加的缓存的过期时间呢? 谢谢
- 请问CheckBoxList控件是怎么向数据库中存数据的??初级!
- 请教关于文件下载的问题
- (高分求救)如何循环插入10万多条纪录
- 在Calendar中click上一月或下一月就自动隐藏了是怎么回事?
- input type=“checkbox” 和<asp:checkbox>有什么区别
- 如何能自动填写网页的内容?
- 请大家对页面控制与布局提点建议...
===
看这条记录查询出来会不会有值.