我想知道这个查询有多少行:
Using ConLoad As SqlConnection = New SqlConnection(constring)
Dim Query As String = "SELECT @@ROWCOUNT AS ROWnum, * FROM Specifications")
ConLoad.Open()
Using cmd As SqlCommand = New SqlCommand(Query, ConLoad)
Response.Write(cmd.ExecuteScalar)
End Using
End Using
在SQL Server Management Studio中执行的此查询返回38,但在我的webform中,它返回0。
我改进了两次发布:
Using ConLoad As SqlConnection = New SqlConnection(constring)
Dim Query As String = "SELECT @@ROWCOUNT AS ROWnum, * FROM Specifications")
ConLoad.Open()
Using cmd As SqlCommand = New SqlCommand(Query, ConLoad)
Response.Write(cmd.ExecuteScalar)
End Using
Using cmd2 As SqlCommand = New SqlCommand(Query, ConLoad)
Response.Write(cmd2.ExecuteScalar)
End Using
End Using
cmd2.ExecuteScalar
的结果是38。
如何在第一时间获得好成绩?
答案 0 :(得分:2)
答案 1 :(得分:2)
@@ROWCOUNT
作为查询结果填充,未在查询中使用,您可以使用COUNT(*)
:
SELECT COUNT(*)
FROM Specifications
或者:
SELECT *
FROM Specifications
PRINT @@ROWCOUNT