当前位置:编程学习 > C#/ASP.NET >>

怎么做筛选数据 的方法


 /// <summary>
        /// 通过id获得商品的信息
        /// </summary>
        /// <param name="id">传入商品id</param>
        /// <returns>将实体返回</returns>
        public static WaresInfo GetWaresById(int id)
        {
            DBHelp db = new DBHelp();
            WaresInfo Wares = null;
            string sql = "select * from WaresInfo where WaresID=@id ";
            //string sq2 = "select * from WaresInfo where WaresID=@Id and Iftype='2'";
            SqlDataReader reader = db.GetReader(sql, new SqlParameter("@id", id));
            if (reader.Read())
                {
                    Wares = new WaresInfo();
                    Wares.WaresID = (int)reader["WaresID"]; ;
                    Wares.WaresNo = (string)reader["WaresNo"];
                    Wares.WaresName = (string)reader["WaresName"];
                    if (reader.IsDBNull(reader.GetOrdinal("WaresImage")))
                    { Wares.WaresImage = null; }
                    else
                    {
                        Wares.WaresImage = (byte[])reader["WaresImage"];
                    }
                    Wares.WaresPoint = (int)reader["WaresPoint"];
                    Wares.WaresSaleNum = (int)reader["WaresSaleNum"];
                    Wares.WaresOldPrice = (decimal)reader["WaresOldPrice"];
                    Wares.WaresAuthor = (decimal)reader["WaresAuthor"];
                    Wares.Iftype = (int)reader["Iftype"];
                    Wares.WaresTime = (DateTime)reader["WaresTime"];
                    Wares.WaresBrand = (string)reader["WaresBrand"];
                    Wares.WaresColour = (string)reader["WaresColour"];
                    Wares.WaresPageNum = (string)reader["WaresPageNum"];
                    Wares.WaresFunction = (string)reader["WaresFunction"];
                    Wares.LogisticsWay = (string)reader["LogisticsWay"];
                }
                reader.Close();
                db.CloseConnection();
                //SqlDataReader reader2 = db.GetReader(sq2, new SqlParameter("@Id", id));
                //if (reader2.Read())
                //{
                //    Wares = new WaresInfo();
                //    Wares.WaresID = (int)reader2["WaresID"]; ;
                //    Wares.WaresNo = (string)reader2["WaresNo"];
                //    Wares.WaresName = (string)reader2["WaresName"];
                //    Wares.WaresImage = (byte[])reader2["WaresImage"];
                //    Wares.WaresPoint = (int)reader2["WaresPoint"];
                //    Wares.WaresSaleNum = (int)reader2["WaresSaleNum"];
                //    Wares.WaresOldPrice = (decimal)reader2["WaresOldPrice"];
                //    Wares.WaresAuthor = (decimal)reader2["WaresAuthor"];
                //    Wares.Iftype = (int)reader2["Iftype"];
                //    Wares.WaresTime = (DateTime)reader2["WaresTime"];
                //    Wares.WaresBrand = (string)reader2["WaresBrand"];
                //    Wares.WaresColour = (string)reader2["WaresColour"];
                //    Wares.WaresPageNum = (string)reader2["WaresPageNum"];
                //    Wares.WaresFunction = (string)reader2["WaresFunction"];
                //    Wares.LogisticsWay = (string)reader2["LogisticsWay"];
                //}
                //reader2.Close();
                //db.CloseConnection();
            return Wares;
        } --------------------编程问答-------------------- DataTable.Select来筛选。或者RowFilter --------------------编程问答-------------------- 就你目前这样子,可以这样玩

public static WaresInfo GetWares(Expression<func<Wares,bool>> expresion)
{
    //如何把expresion解析出来我们另外说
}


外部调用形式

WaresInfo obj=GetWares(p=>p.WaresID==1&&p.WaresName=="aaa")
//相当与sql的 where waresid=1 and wareName='aaa'



最后我们来说一下,怎么把expresion解析出来

具体方法参见:
http://www.cnblogs.com/coolcode/archive/2009/09/28/IQueryBuilder.html
补充:.NET技术 ,  ASP.NET
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,