|   上面是进行查询的三个关键字,其中的三项可随意不同时的赋值,我之前用了下面的代码进行查询:
 但是这些代码显得太复杂,我听我老师说可以只用一句查询语句就可以实现,我百思不得其解,求教各位,这局查询语句该怎么写?复制代码private void find_Click(object sender, EventArgs e)//按学号、姓名、年龄查询
        {                    
            //三个条件的综合判定和查询
            int k= 0;//标志符号,是否该执行SQl查询
            string sql = "select '学号'=No,'姓名'=name,'性别'=Sex,'年龄'=Age,'籍贯'=Native,'家庭住址'=Address,'联系电话'=Telephone from Student  where 1=1";
            if (find_no.Text != "")
               {
                 if ( isNumber(find_no.Text.Trim())==false)//  
                     {
                         MessageBox.Show("你输入的学号不是非负数字,不能查询,请重新输入!!", "提示信息", MessageBoxButtons.OK);
                         find_no.Focus();
                         k++;
                     }
                 else
                 {
                    int i = Convert.ToInt32(this.find_no.Text.ToString());
                    sql += "and No='" + i + "'";
                 }
               }
            if (find_age.Text != "")
               {
                 if (isNumber(find_age.Text.Trim()) == false)
                    {
                        MessageBox.Show("你输入的年龄不是非负数字,不能查询,请重新输入!!", "提示信息", MessageBoxButtons.OK);
                       find.Focus();
                       k++;
                    }
                 else
                    {
                    int j = Convert.ToInt32(this.find_age.Text.ToString());
                    sql += "and Age='" + j + "'";
                    }
                }
            if (find_name.Text != "")
               {
                 sql += "and Name like'%" + find_name.Text + "%'";
               }
            if (k == 0)
            {
                ShowsqlDate(sql);
            }
        }
 |