asp.net中gridview的查询、分页、编辑更新、删除的实例代码

2019-05-20 11:18:45王振洲

    /// 类编编号【FK】
    /// </summary>
    public int CategoryId
    {
        get { return categoryId; }
        set { categoryId = value; }
    }
}

/App_Code/ProductOper.cs


using System;
using System.Collections.Generic;

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),