2013-02-27 60 views
1

喜行的数目,但我alwyas找回-1.Here是我的代码:再回到表返回-1我tryng算表中的行数

using (connection = new SqlConnection(connectionString)) 
{ 
     connection.Open(); 
     SqlCommand command = new SqlCommand("CountBooks", connection); 
     command.CommandType = CommandType.StoredProcedure; 
     numberOfBooks = command.ExecuteNonQuery(); 
} 

这里是我的查询:

SELECT COUNT(*) FROM Books 

如何才能得到正确的结果?

回答

5

使用ExecuteScalar而不是ExecuteNonQuery。