要检索sql中的记录表计数并在网页中显示总计数? [英] To retrieve table count of records in sql and display in total count in web page?
本文介绍了要检索sql中的记录表计数并在网页中显示总计数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的,
我有1张桌子,其中包含工作记录和汽车记录
在网页2标签,1个标签显示车数和第2标签显示工作计数
我写下面的代码:
try
{
SqlConnection con = new SqlConnection(ConfigurationManager。 ConnectionStrings [ masthanConnectionString]。ConnectionString);
con.Open();
string str = 从productdetails中选择count(*),其中Title ='cars';
SqlCommand cmd = new SqlCommand(str,con);
// cmd.Parameters.AddWithValue(cmd,con);
Label1.Text = cmd.ExecuteNonQuery()。ToString();
// cmd.ExecuteNonQuery();
con.Close();
}
catch
{
// < span class =code-comment> Label1.Text =;
}
但是我输出了-1
数据库总车数6但这里只显示-1
请回复我是什么错误
和我解决这个
解决方案
试试这个
Label1.Text = cmd.ExecuteScalar( );
Dear all,
I have 1 table that table contain jobs records and cars records
In web page 2 lables, 1 lable display cars count and 2nd lable display jobs count
I write code below:
try
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["masthanConnectionString"].ConnectionString);
con.Open();
string str = "select count(*) from productdetails where Title='cars'";
SqlCommand cmd = new SqlCommand(str, con);
//cmd.Parameters.AddWithValue("cmd",con);
Label1.Text = cmd.ExecuteNonQuery().ToString();
//cmd.ExecuteNonQuery();
con.Close();
}
catch
{
//Label1.Text = "";
}
but i got output -1
in database total cars count 6 but here display -1 only
please reply me what mistake
and i resolve this
解决方案
try this
Label1.Text = cmd.ExecuteScalar();
这篇关于要检索sql中的记录表计数并在网页中显示总计数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文