DAL层联合查询及条件查询方法(常用)

首先我们要把SqlHelper给写完整,在我们往期博客内有写,可以点击主页查看哦~

1.我们首先要把Sql语句提前写好,在确认能运行的情况下再来写入查询方法内~

select ProInfo.*,ProType.TypeName from ProInfo,ProType where ProInfo.Protype=ProType.TypeID

我们用平时的案例来写这个查询,相信大家都可以看明白。

2.将sql语句带入进行条件查询

 public static DataTable Select(int protype = 0, string proname = "")
        {
            string sql = "select ProInfo.*,ProType.TypeName from ProInfo,ProType where ProInfo.Protype=ProType.TypeID";
            if (protype!=0)
            {
                sql += " and Protype=" + protype;
            }

            if (proname!="")
            {
                sql += " and proname like '%" + proname + "%'";
            }

            return SqlHelper.Cx(sql);
        }
protype为类型,
proname为名字,
大家在写过BLL层后在UI层就可以使用了~我们下期见~
原文地址:https://www.cnblogs.com/NeatFan/p/13175834.html