0
Im选择查询中有多少行的计数。我需要将它分配给一个int变量。我怎么做到这一点?查询返回行数并分配给Int变量
Display.aspx.cs
**int TotalYesVotes;**
Ratings GetYesVotes = new Ratings();
DataTable DATotalYesVotes = GetYesVotes.GetTotalYesVotes();
**//How do i assign that count to TotalYesVotes**
业务层
public DataTable GetTotalYesVotes()
{
DLRatings DlTotalyesVotes = new DLRatings();
return DlTotalyesVotes.GetTotalYesVotes();
}
我的数据层
public DataTable GetTotalNoVotes()
{
//get database connection string from config file
string strConectionString o= ConfigurationManager.AppSettings["DataBaseConnection"];
//set up sql
string StrSql = "SELECT COUNT(*) AS Expr1 FROM Ratings WHERE (PicRating = 2) AND (PicID = 2)";
DataTable dt = new DataTable();
using (SqlDataAdapter daObj = new SqlDataAdapter(StrSql, strConectionString))
{
//fill data table
daObj.Fill(dt);
}
return dt;
}
如果'GetTotalNoVotes'的目的是检索标量值,为什么要返回一个数据表? –