Return to Snippet

Revision: 11682
at February 13, 2009 14:04 by wrburgess


Initial Code
Function SelectByScalar(ByVal strCriteria As String) As Integer

  Dim objConn As New SqlConnection()
  Dim objCmd As New SqlCommand()
  Dim strSQL As String

  objConn = New SqlConnection(ConfigurationManager.ConnectionStrings("[connection]").ConnectionString)
  objCmd.Connection = objConn
  objCmd.Connection.Open()

  strSQL = "SELECT Count(ID) "
  strSQL += "FROM [table] "
  strSQL += "WHERE [field] LIKE '%" & strCriteria & "%';"

  objCmd = New SqlCommand(strSQL, objConn)
  SelectByScalar = objCmd.ExecuteScalar()

  objCmd.Dispose()
  objConn.Dispose()
  objConn.Close()

End Function

Initial URL


Initial Description


Initial Title
Execute SQL Scalar Select with ASP.NET 3.5

Initial Tags
sql, aspnet

Initial Language
ASP