当前位置:编程学习 > C#/ASP.NET >>

搜索问题

  当我选择=号,txtSeach文本框为空时,单击"搜索"按钮,要求显示所有内容
请大家帮我看一下,哪里有问题

string str = "";
         string strcomm = "";



         //判断downSelect2中所选择的项
         if (Cdrop1.SelectedItem.ToString() == "=")
         {
             str = "=";
         }

         if (Cdrop1.SelectedItem.ToString() == ">")
         {
             str = ">";
         }

         if (Cdrop1.SelectedItem.ToString() == "<")
         {
             str = "<";
         }

         if (Cdrop1.SelectedItem.ToString() == ">=")
         {
             str = ">=";
         }

         if (Cdrop1.SelectedItem.ToString() == "<=")
         {
             str = "<=";
         }

         if (Cdrop1.SelectedItem.ToString() == "<>")
         {
             str = "!=";
         }

         /*//判断txtSerach文本框是否为空
         if (this.txtSerach.Text.ToString() == "" | this.txtSerach.Text.ToString() == null)
         {
             Response.Write("<script>alert('请输入查找内容!');</script>");
         }*/



         //判断txtSerach文本框是否为空
        if (this.txtSerach.Text.Trim().ToString() != "" | this.txtSerach.Text.Trim().ToString() != null)
         {
             
             //按"公司编号"查找
             if (Cdrop2.SelectedItem.ToString() == "公司编号")
             {
                 if (Cdrop1.SelectedItem.ToString() == "like")
                 {
                     str = "like";
                     strcomm = "select * from EasComInfo where CoCode  " + str.Trim().ToString() + "  '%" + txtSerach.Text.Trim().ToString() + "%'";
                 }
                 else
                 {
                     if (Cdrop1.SelectedItem.ToString() == "begin")
                     {
                         str = "like";
                         strcomm = "select * from EasComInfo where CoCode  " + str.Trim().ToString() + "  '" + txtSerach.Text.Trim().ToString() + "%'";

                     }
                     else
                     {
                         if (this.txtSerach.Text.Trim().ToString() != "" | this.txtSerach.Text.Trim().ToString() != null)
                         {
                             strcomm = "select * from EasComInfo where CoCode " + str.Trim().ToString() + " '" + txtSerach.Text.Trim().ToString() + "'";
                         }
                         
                     }
                 }
             }
             //按"公司中文名称"查找
             if (Cdrop2.SelectedItem.ToString() == "公司中文名称")
             {
                 if (Cdrop1.SelectedItem.ToString() == "like")
                 {
                     str = "like";
                     strcomm = "select * from EasComInfo where CoName_Ch  " + str.Trim().ToString() + "  '%" + txtSerach.Text.Trim().ToString() + "%'";
                     
                     
                 }
                else
                 {
                     if (Cdrop1.SelectedItem.ToString() == "begin")
                     {
                         str = "like";
                         strcomm = "select * from EasComInfo where CoName_Ch  " + str.Trim().ToString() + "  '" + txtSerach.Text.Trim().ToString() + "%'";
                     }
                     else{
                         strcomm = "select * from EasComInfo where CoName_Ch " + str.Trim().ToString() + " '" + txtSerach.Text.Trim().ToString() + "'";
                     }
                 }
             }
             //按"公司董事名称"查找
             if (Cdrop2.SelectedItem.ToString() == "董事名称")
             {
                 if (Cdrop1.SelectedItem.ToString() == "like")
                 {
                     str = "like";
                     strcomm = "select * from EasComInfo where CoHKDorector  " + str.Trim().ToString() + "  '%" + txtSerach.Text.Trim().ToString() + "%'";
                 }
                 else
                 {

                     if (Cdrop1.SelectedItem.ToString() == "begin")
                     {
                         str = "like";
                         strcomm = "select * from EasComInfo where CoHKDorector  " + str.Trim().ToString() + "  '" + txtSerach.Text.Trim().ToString() + "%'";
                     }
                     else
                     {
                         strcomm = "select * from EasComInfo where CoHKDorector " + str.Trim().ToString() + " '" + txtSerach.Text.Trim().ToString() + "'";
                     }
                 }
             }

         } --------------------编程问答-------------------- void xxx(string where) 
{
strcomm   =   "select   *   from   EasComInfo  ;
if(Where!="")
{
   strcomm+=" where "+where;
 } 
}
-------------------------------------
其实你只要写一个就可以了!
补充:.NET技术 ,  ASP.NET
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,