string a = this.textBox1.Text;
string se1 = "select ID from [zhubiao] where ID = &a";
if ((!String.IsNullOrEmpty(se1)))
{
  MessageBox.Show("输入ID已经存在,是否要保存?");
 }我的目的是判断TextBox中的内容在表中是否重复,可是现在我在TextBox无论输入什么内容,都提示存在了,到底哪里有问题呢??谢谢指教!

解决方案 »

  1.   

    string se1 = "select ID from [zhubiao] where ID ='"+a+"'"; 
      

  2.   

    string se1 = "select ID from [zhubiao] where ID = &a";
    se1 等于的是 select ID from [zhubiao] where ID = &a 值
    而不是数据库中取出来的 id
      

  3.   


    //string se1 = "select ID from [zhubiao] where ID = &a"; 
    //上面的改为下面
    string se1 = "select ID from [zhubiao] where ID = " + a; 
      

  4.   

    根本就没查询啊
    你把select ID from [zhubiao] where ID = &a这个字符串赋值给se1 
    然后判断他是否为空,当然是这个结果了
      

  5.   


      你已经给se1 赋值了:"select ID from [zhubiao] where ID = &a"; 
      sel 是有值的
      这样判断都是成立的,所以会提示存在了
      

  6.   

    晕,你还没有写查询语句呢SqlConnection conn = new SqlConnection();..........
      

  7.   

    string sel = string.Format("select ID from [zhubiao] where ID = '{0}'",a);
      

  8.   

    看了各位高手的见解,真脸红啊,好像是只是赋值,而不是执行SQL后的结果谢谢!!
      

  9.   

    我按照上面几位的改法改了之后,还是不行啊,请问我该怎么改啊
    我的目的就是判断输入是否与表中的内容有重复,难道是String.IsNullOrEmpty有问题啊?
      

  10.   

    首先你的想法就是错的。。String.IsNullOrEmpty根本不会用到这个方法。
    首先"select Count(*) from [zhubiao] where ID="+a如果在数据库中查询后,如果影响值大于0就是存在,不大于0就是不存在。做那么多干什么。
    还有就是看看ado.net吧