wo kao 就这么简单
//把TextBox的Name设成你数据库字段的Name,TextBox的Tag就放字段的类型 int、char
//然后在按钮事件中添加
StringBuilder sb = new StringBuilder();
sb.Append("Select * from 表名 Where 1=1");
foreach (var c in this.Controls)
{
if (c is TextBox)
{
var txt = c as TextBox;
if (txt != null && txt.Text.Trim() != "")
{
bool isChar = (txt.Tag.ToString() == "char");
sb.Append(" And " + txt.Name + ""+(isChar?" Like ":"=")+""+(isChar?"'%":"")+"" + txt.Text.Trim() + ""+(isChar?"%'":"")+"");
}
}
}
//或者全部为空的话就不查询 哈哈
if (sb.ToString().IndexOf("And") == -1) return;
//这里执行sql语句就行了
PS:手写判断会死人的 哈哈