在标签中显示从计数查询中提取的数字或行 [英] displaying numbers or rows excuted from count query in label

查看:51
本文介绍了在标签中显示从计数查询中提取的数字或行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以告诉我..如何在db表中显示使用标签中的count sql查询执行的行数.例如,如果我们有一个查询

Can any one tell me .. how to show the nmber of rows in a db table which are executed using count sql query in a label. for example if we have a query

"Select Count(*) FROM Categories where CategoryName ='" + p.addcat + "'";



我们说通过这个计数查询得到两行.我想在标签控件中显示count = 2.我该怎么办?



and we lets say we get two rows by this count query. i want to show that count=2 in a label control.. how can i do it??

推荐答案

一旦数据表中有数据,请尝试类似:
once you have data in the data table , try something like :
Label1.Text = datatable.Rows[0][0].ToString();


尽管如果仅从数据库中获得一个值,则ExecuteScalar()会更好.


Although if you are only getting one value out of the database, ExecuteScalar() would be better.


这篇关于在标签中显示从计数查询中提取的数字或行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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