asp.net中gridview的查询、分页、编辑更新、删除的(2)

分页标题#e#

using System.Data.SqlClient;
/// <summary>
///ProductOper 的摘要说明
/// </summary>
public class ProductOper
{
    /// <summary>
    /// 1,GetAll
    /// </summary>
    /// <returns></returns>
    public static IList<ProductInfo> GetAll()
    {
        IList<ProductInfo> dals = new List<ProductInfo>();
        string sql = "select productId,productName,unitprice,special,categoryId from Product order by productId desc";

//1,创建连接对象
        SqlConnection con = new DBConnection().Con;
        //2,创建命令对象
        SqlCommand cmd = con.CreateCommand();

//3,把sql语句付给命令对象
        cmd.CommandText = sql;

//4,打开数据连接
        con.Open();
        try
        {
            using (SqlDataReader sdr = cmd.ExecuteReader())
            {
                while (sdr.Read())
                {
                    ProductInfo dal = new ProductInfo()
                    {
                        ProductId = sdr.GetInt32(0),
                        ProductName = sdr.GetString(1),
                        Unitprice = sdr.GetDecimal(2),
                        Special = sdr.GetString(3),
                        CategoryId = sdr.GetInt32(4)
                    };

dals.Add(dal);
                }
            }
        }
        finally
        {
            //,关闭数据连接(释放资源)
            con.Close();
        }
        return dals;
    }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjgpxz.html