在C Sharp中选择SQL Server Querry [英] select sql server querry in c sharp

查看:222
本文介绍了在C Sharp中选择SQL Server Querry的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SELECT *从sec_users_ids中,其中UserName =(" + userName +'')"

我正在将Querry传递给command.commandtext(str_querry)ant,然后传递command.executenonquerry()
我怎么知道那里是否存在特定数据
我已经创建了连接,并且.......

SELECT * From sec_users_ids where UserName = (''"+ userName +"'')"

i am passing a querry to command.commandtext(str_querry) ant then command.executenonquerry()
how i come to know that that particular data is present there or not
i already created connection and .......

推荐答案

尝试此

try this

SELECT count(*) From sec_users_ids where UserName = (''"+ userName +"'')"

int i = Convert.ToInt32(command.ExecuteScalar());

if ( i == 0)
   //User does not exist
else
   //User exist


你好,

一种实现方法是使用sqladapter将数据放入数据表,然后检查count的条件是否大于等于0的行数.


谢谢
sanjeev
hello,

one way of doing this is take data into a datatable using sqladapter and then check a condition for rowcount if count is greater than 0 that means data is there.


thanks
sanjeev


要获取记录,可以使用数据读取器代替executenonquery
to get the record you may use datareader instead of executenonquery


这篇关于在C Sharp中选择SQL Server Querry的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆