DAL层通用查询不能返回DataTable DataSet
public List<Products> QueryProduct2(double unitPrice)
//【1】封装查询,并提交查询
stringsql="select Productid,ProductName,UnitPrice,Unit from Products where UnitPrice>@UnitPrice"
SqlParameter[] param =new SqlParameter[]
{
new SqlParameter("@UnitPrice",unitPrice)
};
SqlDataReader reader=SQLHelper.ExecuteReader(sql, param);
List<Products> list = new List<Products>();
//【2】读取数据列表
while (reader.Read())
{
list.Add(new Products
{
Productld = reader["Productld"].ToString(),
ProductName = reader["ProductName"].ToString()
UnitPrice = Convert.ToDouble(reader["UnitPrice"])
Unit =reader["Unit"].ToString()
//Discount=Convert.Tolnt32(reader["Discount"])//这个是不能用的,因为查询中没有Discount
});
reader.close();
return list;
}
//按条件查询
private void btnQuery_Click(object sender, EventArgse)
{
//DataTabledt=pManager.QueryProduct1(Convert.ToDouble(this.txtQuery.Text.Trim()));
//this.dgvProductList.DataSource =dt;
//执行查询
List
//绑定数据
this.dgvProductList.DataSource =list;
}
浙公网安备 33010602011771号