asp.net三层问题
数据库中存在表yjjl(juid,store_coode,jdate,store_name,store_address,jycontent)
我想得到:在这张表中根据store_code分组,并得到每组的数量,即select store_code ,count(store_code)from yjjl group by store_code
我想把查询出来的结果放到一个集合中,然后把这个集合绑定到控件中,我如何在数据访问层得到这个集合? 集合 数据库 ASP.NET
[解决办法]
参考动软生成器http://www.cnblogs.com/ltp/archive/2008/10/01/1302689.html
[解决办法]
这是最基本的数据库查询。
楼主还有很多路需要走,先看看基础的查询吧。
[解决办法]
/// <summary>
/// 获得数据列表
/// </summary>
public DataSet GetList(string strWhere)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select XXX From XXX ");
strSql.Append(" FROM Staff ");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
return Query(strSql.ToString());
}
/// <summary>
/// 执行查询语句,返回DataSet
/// </summary>
/// <param name="SQLString">查询语句</param>
/// <returns>DataSet</returns>
public static DataSet Query(string SQLString)
{
SqlConnection connection = new SqlConnection(connectionString);
DataSet ds = new DataSet();
try
{
connection.Open();
SqlDataAdapter command = new SqlDataAdapter(SQLString, connection);
command.Fill(ds, "ds");
}
catch (System.Data.SqlClient.SqlException ex)
{
throw new Exception(ex.Message);
}
return ds;
}