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