计算数据库中的数据值 [英] counting data value in database
问题描述
如果我写以下代码:
的SqlCommand mycommand的新=的SqlCommand( SELECT * FROM [student_reg] WHERE [std_id] = 'c101234',MyConnection的);
它选择保存id = c101234的所有值,但是如何计算在C#中包含id c101234的行数...
帮助提前。
提前感谢。
If i write the following code:
SqlCommand myCommand = new SqlCommand("select * FROM [student_reg] WHERE [std_id]= 'c101234 ' ", myConnection);
it select all value that hold id=c101234 and but how can I count that how many rows there are that contains the id c101234 in C#...
help to ahead.
thanks in advance.
推荐答案
您的查询应该是:
Your query should be :
select count(*) from [student_reg] WHERE [std_id]= 'c101234'
编辑:
另请阅读: http://msdn.microsoft.com/en-us/library/system.data.sqlc lient.sqlcommand.executescalar%28v = vs.110%29.aspx [ ^ ]
编辑2:
Edit :
Also read this : http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executescalar%28v=vs.110%29.aspx[^]
Edit 2:
SqlCommand myCommand = new SqlCommand("select count(*) from [student_reg] WHERE [std_id]= 'c101234' ", myConnection);
int count = (Int32) myCommand.ExecuteScalar();
访问这里......
从数据库到c-sharp的检索总计数 [ ^ ]
Visit Here...
retrieving-total-count-from-database-to-c-sharp[^]
这篇关于计算数据库中的数据值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!