做了一个搜索查询,但只能查数字,查文本、字母或者文本、字母+数字就报错,报错见截图,帮忙看看问题出在哪,拜谢


<style type="text/css">
.search_list{clear:both;overflow:hidden}
.search_list li{clear:both;padding:0px 5px 5px 5px;margin-bottom:10px;border-bottom:1px dotted #cccccc;overflow:hidden}
.search_list li .name{float:left;height: 80px;line-height: 80px;width:1000px;text-align: center;font-size: 50px;}
.search_list li .content{width:1000px;float:right;text-align: center}
</style>
<script language="c#" runat="server">
string Sql_Format(string str,bool isFuzzyQuery)
{
if(string.IsNullOrEmpty(str)){return string.Empty;}
str=Server.UrlDecode(Server.UrlEncode(str).Replace("%00",""));
str=str.Replace("'","''");
str=str.Replace("\"","\"");
if(isFuzzyQuery)
{
str=str.Replace("[]","[[]]");
str=str.Replace("[","[[]");
str=str.Replace("]","[]]");
str=str.Replace("_","[_]");
str=str.Replace("%","[%]");
str=str.Replace("^","[^]");
}
return str;
}
protected string SubStr(string pa_bianhao,int Title_Num,bool HtmlEncode)
{
if(Title_Num==0)
{
return ""; }
else
{
System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("[\u4e00-\u9fa5]+", System.Text.RegularExpressions.RegexOptions.Compiled);
char[] stringChar = pa_bianhao.ToCharArray();
StringBuilder sb = new StringBuilder();
int nLength = 0;
for(int i = 0; i < stringChar.Length; i++)
{
if (regex.IsMatch((stringChar[i]).ToString()))
{
nLength += 2;
}
else
{
nLength = nLength + 1;
}
if(nLength <= Title_Num)
{
sb.Append(stringChar[i]);
}
else
{
break;
}
}
if(sb.ToString() != pa_bianhao)
{
sb.Append("...");
}
if(HtmlEncode)
{
return Server.HtmlEncode(sb.ToString());
}
else
{
return sb.ToString();
} }
}
</script>
<ul class="search_list">
<%
string Table="zhengshu";//搜索的表名称
string sql_condition="";
string ky=Request.QueryString["ky"];
if(string.IsNullOrEmpty(ky))
{
Response.Write("<li class='noitem'>对不起,没有您要找的记录。</li>");
}
else
{
string url="";
ky=Sql_Format(ky.Trim(),true);
ky=SubStr(ky,30,true).Replace("...","");
sql_condition+=" and pa_bianhao like "+ky+"";
string sql="select * from "+Table+" where site_id="+Site_Id+" and checked=1 and source_id=0 "+sql_condition;
string countsql="select count(id) as co from "+Table+" where site_id="+Site_Id+" and checked=1 and source_id=0"+sql_condition;
DataTable dt=Get_Data(sql,countsql,10);
DataRow dr;
if(dt.Rows.Count>0)
{ for(int i=0;i<dt.Rows.Count;i++)
{
dr=dt.Rows[i]; //说明:给dr赋值
url=Detail_Url(dr,Table);
%>
<li><p class="name"><%=dr["title"].ToString()%></p>
<p class="content">
<%=dr["content"].ToString()%>
</p>
</li>
<%
}
}
else
{
Response.Write("<li class='noitem'>对不起,没有查询到匹配的记录。</li>");
}
}
%>
</ul>
<script type="text/javascript">
var ky="<%=Server.HtmlEncode(Request.QueryString["ky"])%>";
if(ky!="" && Id("searchky")!=null)
{
Id("searchky").value=ky;
}
</script>