计算表中可用的记录。 [英] count the record available in the table.

查看:102
本文介绍了计算表中可用的记录。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一条记录来计算记录值;

这些计数值会显示在标签上;

i写下这些代码......




SqlConnection con2 = new SqlConnection(ConfigurationManager.ConnectionStrings [sst]。ToString());

con2 .Open();

SqlCommand c1 = new SqlCommand(从mastertable选择COUNT(托管),其中[user] ='+ lblnam.Text +',con2);

SqlDataAdapter da1 = new SqlDataAdapter(c1.CommandText,con2);

DataSet ds1 = new DataSet();



da1 .Fill(ds1);

lbhosttake.Text = ds1.Tables [0] .Rows.Count.ToString();

con2.Close();



这里lbhosttake是一个标签值,显示计数值。实际上,因为我运行它只显示计数值1.

天气记录是是否可以,天气有很多记录,但每次只显示1个..



什么可以我做。因此它将显示总计数值。

i wrote a record to count the record value;
and these count value will show on the lable;
i write these code.....


SqlConnection con2 = new SqlConnection(ConfigurationManager.ConnectionStrings["sst"].ToString());
con2.Open();
SqlCommand c1 = new SqlCommand("Select COUNT(hosting) from mastertable where [user]='" + lblnam.Text + "'", con2);
SqlDataAdapter da1 = new SqlDataAdapter(c1.CommandText, con2);
DataSet ds1 = new DataSet();

da1.Fill(ds1);
lbhosttake.Text = ds1.Tables[0].Rows.Count.ToString();
con2.Close();

here lbhosttake is a lable that will show the count value.. Actually as i run it shows the count value only 1.
Weather the record is avaiable or not, weather has many record,, but it shows only 1 every time..

what can i do. so that it will show total counting value.

推荐答案

使用 SqlCommand.ExecuteScalar Method [ ^ ]



use SqlCommand.ExecuteScalar Method[^]

con2.Open();
SqlCommand c1 = new SqlCommand("Select COUNT(hosting) from mastertable where [user]='" + lblnam.Text + "'", con2);
int count=(int)c1.Executescalar();
lbhosttake.Text =count.ToString();





从中选择COUNT(托管)。 。只返回单个值(一行),因此行数将为1。您需要使用 Executescalar 方法读取返回行的值,或者读取 ds1.Tables [0] .Rows [0] .Cels的值[0] value



Select COUNT(hosting) from .. return only single value ( one row), so the row count will be one. You need to read the value of the return row with Executescalar method or read the value of ds1.Tables[0].Rows[0].Cels[0] value


这篇关于计算表中可用的记录。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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