Execute SQL Scalar Select with ASP.NET 3.5


/ Published in: ASP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. Function SelectByScalar(ByVal strCriteria As String) As Integer
  2.  
  3. Dim objConn As New SqlConnection()
  4. Dim objCmd As New SqlCommand()
  5. Dim strSQL As String
  6.  
  7. objConn = New SqlConnection(ConfigurationManager.ConnectionStrings("[connection]").ConnectionString)
  8. objCmd.Connection = objConn
  9. objCmd.Connection.Open()
  10.  
  11. strSQL = "SELECT Count(ID) "
  12. strSQL += "FROM [table] "
  13. strSQL += "WHERE [field] LIKE '%" & strCriteria & "%';"
  14.  
  15. objCmd = New SqlCommand(strSQL, objConn)
  16. SelectByScalar = objCmd.ExecuteScalar()
  17.  
  18. objCmd.Dispose()
  19. objConn.Dispose()
  20. objConn.Close()
  21.  
  22. End Function

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.