C#中如何对数据库的值进行操作
我现在遇到了个小问题,就是我连接SQL数据库后,使用SELECT语句查询表里是否有符合条件的数据,然后把值传递给SqlDataAdapter,但是我现在想要判断从数据库返回来的结果是否查询到了符合条件的数据,由于3年没接触这个了,所以很多不记得了,如果我的这个思路是错的,请有时间的大侠们帮我写一段,感激啊,全部的分都奉上
2012-03-01 18:08
程序代码:string strConn = "server=服务器名称;uid=登陆服务器用户名;pwd="密码;database=数据库名称";
SqlConnection conn = new SqlConnection(strConn);
conn.Open();//打开连接
string strExcel = "";
SqlDataAdapter myCommand = null;
strExcel = "select Count(*) from 表名 where 条件";
myCommand = new SqlDataAdapter(strExcel, strConn);
int a =myCommand. ExecuteScalar(strExcel);
conn.Close();
if( a > 0)
{
Messagebox.Show("有符合条件的数据");
}
else
{
Messagebox.Show("没有符合条件的数据");
}
2012-03-02 08:41
2012-03-02 08:56
2012-03-02 21:25