string sqlquery = "select * from Person where psnNo LIKE'%" + tbContent.Text + "%'and psnName LIKE'%" + tbContent.Text + "%' and psnSex LIKE'%" + tbContent.Text + "%' and psnAge LIKE'%" + tbContent.Text + "%' and psnAddress LIKE'%" + tbContent.Text + "%'and psnDuty LIKE'%" + tbContent.Text + "%'"; 有问题吧,你试下,如果 tbContent.Text="0001"那么,sqlquery= select * from Person where psnNo LIKE '%0001%' and psnName like '%0001%' and psnSex like '%0001%'...
我觉得你是不是想这样表达吧,假如查询类型选择的控件是 dlType string sqlquery = "select * from Person"; if (dlType.Text =="学号") { sqlquery +=" where psnNo LIKE '%" + tbContent.Text + "%'"; } else if (dlType.Text =="姓名") { sqlquery +=" where psnName LIKE '%" + tbContent.Text + "%'"; } ...
把AND 改OR
+ tbContent.Text + "%'and psnName LIKE'%"
+ tbContent.Text + "%' and psnSex LIKE'%"
+ tbContent.Text + "%' and psnAge LIKE'%"
+ tbContent.Text + "%' and psnAddress LIKE'%"
+ tbContent.Text + "%'and psnDuty LIKE'%"
+ tbContent.Text + "%'";
有问题吧,你试下,如果 tbContent.Text="0001"那么,sqlquery=
select * from Person where psnNo LIKE '%0001%' and psnName like '%0001%' and psnSex like '%0001%'...
string sqlquery = "select * from Person";
if (dlType.Text =="学号")
{
sqlquery +=" where psnNo LIKE '%" + tbContent.Text + "%'";
}
else if (dlType.Text =="姓名")
{
sqlquery +=" where psnName LIKE '%" + tbContent.Text + "%'";
}
...
如果是精确查找的时候,如果输入一个“果”字,为什么出现这个错误提示“在将 varchar 值 '果' 转换成数据类型 smallint 时失败。”???/
把AND 改OR 如果是精确查找的时候,如果输入一个“果”字,为什么出现这个错误提示“在将 varchar 值 '果' 转换成数据类型 smallint 时失败。”??????
如果是精确查找的时候,如果输入一个“果”字,为什么出现这个错误提示“在将 varchar 值 '果' 转换成数据类型 smallint 时失败。”???/用这个方法应该就不会了
如果是精确查找的时候,如果输入一个“果”字,为什么出现这个错误提示“在将 varchar 值 '果' 转换成数据类型 smallint 时失败。”???/用这个方法应该就不会了,但如查是数字型的字段要变一下如年龄:
if (dlType.Text =="学号")
{
sqlquery +=" where psnNo LIKE '%" + tbContent.Text + "%'";
}
else if (dlType.Text =="姓名")
{
sqlquery +=" where psnName LIKE '%" + tbContent.Text + "%'";
}
else if (dlType.Text =="年龄")
{
sqlquery +=" where psnAge =" + tbContent.Text;
}