"select * from 用户列表 where exists (select * from 用户列表 where 用户名=" + textBox1.Text +" and 密码="+ textBox2.Text +")";
在C#中执行了这样一段查询语句,exists是返回BOOLEAN的值,我在C#中如何获取这一返回值

解决方案 »

  1.   

    你返回的恐怕不是bool,
    你可以用dataset/datatable获取你这句的查询值(dataadapter),只要检测 ds.rows.count 是否为0即可
      

  2.   

    exists 只是 where的子句因为select *
    真正返回的还是结果集
      

  3.   

    用SqlCommand的ExecuteScalar方法不就可以返回第一行第一列的值,你可以看看到底是个什么值,然后判断。
      

  4.   

    你这样做的结果肯定是错的EXISTS里面和外面是应该关联的select * from 用户列表 where exists (select 1 from 用户列表 a where a.主键 = 用户列表.主键 and 用户名=" + textBox1.Text +" and 密码="+ textBox2.Text +")"
    我不知道楼主到底要干吗,是否是发现查询的结果错了,要找到错在哪?如果是这样的话,上面的代码应该能解决你的问题。如果你要获得结果的话,我还真不知道,等待知道的高手作答~
      

  5.   

    我是想找到是否在数据库中存在该用户,存在返回true,不存在返回FALSE
      

  6.   

    select count(*) from tb where ...
    (int)cmd.ExecuteScalar();
      

  7.   


    if exists(select * from  hehe where [B]=2) 
    select 1
    else
    select 2
      

  8.   

    执行完sql,判断count值>0 则true
      

  9.   


    同时,楼主这种方式的sql语句容易被注入