我如何在标签中写上计数数字? [英] how i write the count number in a lable?
本文介绍了我如何在标签中写上计数数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用以下代码来计算MSSQL 2005 DB中表中的行数.
但是,我应该如何编写C#代码来获取数字?
I use the following code to count the number of rows in a table in MSSQL 2005 DB.
But, how should I write the C# code to get the number?
SqlConnection objcon = new SqlConnection();
objcon.ConnectionString = "Data source=localhost; Initial catalog=BRIDGES_DB; User ID=sa; password=123;";
SqlCommand objcom = new SqlCommand();
objcom.CommandType = CommandType.Text;
objcom.CommandText = "SELECT COUNT(marks_org) FROM activity_result";
objcom.Connection = objcon;
objcon.Open();
if (dr.Read())
{
Label1.Text=?
}
objcon.Close();
推荐答案
您可以通过执行以下操作找到该值:
You would find the value by doing the following:
Label1.Text = dr[0].ToString();
但是,我在任何地方都看不到dr的定义.确保您正在执行以下操作:
However, I don''t see dr defined anywhere. Make sure you are doing the following:
SqlDataReader dr = objcom.ExecuteReader();
在执行if语句之前.
这是一个有效的教程,可以为您指明正确的方向:
http://www.akadia.com/services/dotnet_data_reader.html [
before you do the if statement.
Here is a working tutorial that will point you in the right direction:
http://www.akadia.com/services/dotnet_data_reader.html[^]
这篇关于我如何在标签中写上计数数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文