Posted By

wrburgess on 02/13/09


Tagged

sql aspnet Scalar


Versions (?)

Execute SQL Scalar Select with ASP.NET 3.5


 / Published in: ASP
 

  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  

You need to login to post a comment.