/ Published in: ASP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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