我想知道有多少行獲得與此查詢:@@ ROWCOUNT返回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
End Using
在SQL Server Management Studio中執行該查詢返回38,但在我的網頁表單它返回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
我該如何做才能在第一時間取得好成績?
選擇表的所有記錄,只計算其元素效率很低,請改用'SELECT COUNT(*)FROM yourTable' –