#region 通过带参数的Sql语句来实现模糊查询(多条件查询)

            StringBuilder sb = new StringBuilder("select * from books");
List<string> listWheres = new List<string>();
List<SqlParameter> listParams = new List<SqlParameter>();
if (txtBookName.Text.Trim().Length > )
{
listWheres.Add(" bookName like @bkName ");
listParams.Add(new SqlParameter("@bkName", "%" + txtBookName.Text.Trim() + "%"));
} if (txtPubName.Text.Trim().Length > )
{
listWheres.Add(" PublishName like @pubName ");
listParams.Add(new SqlParameter("@pubName", "%" + txtPubName.Text.Trim() + "%"));
} if (txtPrice.Text.Trim().Length > )
{
listWheres.Add(" Price = @price");
listParams.Add(new SqlParameter("@price", double.Parse(txtPrice.Text.Trim())));
}
if (listWheres.Count > )
{
sb.Append(" where ");
string wheres = string.Join(" and ", listWheres.ToArray());
sb.Append(wheres);
}
MessageBox.Show(sb.ToString()); SqlParameter[] pms = listParams.ToArray(); #endregion

最新文章

  1. C#设计模式-建造者模式
  2. 1.13 linux笔记
  3. java 多线程1
  4. bzoj 4448 [Scoi2015]情报传递(主席树,LCA)
  5. c++ 发布动态.so
  6. scheme I/0 输入输出操作
  7. A Byte of Python 笔记(3)运算符和表达式
  8. 原来,负载均衡可以这样用,多核CPU可以这样用
  9. PHP函数register_shutdown_function的使用
  10. HighCharts之2D面积图
  11. 使用Kubeadm部署Kubernetes1.14.1集群
  12. AppBoxFuture(一): Hello Future!
  13. nginx部署django应用
  14. 基于git命令的代码统计方法
  15. 从零开始学 Web 之 jQuery(四)元素的创建添加与删除,自定义属性
  16. 安装PG3.0详细教程附图
  17. Linux文件系统中的inode节点详细介绍
  18. linux笔记_day08
  19. as3 程序域
  20. nginx并发连接控制模块ngx_http_limit_conn_module

热门文章

  1. 会吓人的概念证明病毒: Chameleon
  2. Codeforces Gym 100187D D. Holidays 排列组合
  3. 你应该知道的c# 反射详解
  4. 编辑器TP
  5. python类型转换、数值操作(转)
  6. acdreamoj1108(The kth number)
  7. MySQL auto_increment实现
  8. PCA MATLAB
  9. Jackson学习二之集合类对象与JSON互相转化--转载
  10. &lt;转&gt;一道面试题比较synchronized和读写锁