Home » .NET 4.0 » Record Count Using Stored Procedure

Record Count Using Stored Procedure


Imports System.Data.SqlClient
Partial Class mb_app_promo
 Inherits System.Web.UI.Page
  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) _
                          Handles Me.Load
   G1.Text = "500"
   Dim connString As String
   connString = ConfigurationManager.ConnectionStrings("myConnString").ToString
   Dim conn As New SqlConnection(connString)
     Try
       conn.Open()
       Dim cmd As New SqlCommand("myStoredProcedure", conn)
       Dim count As Integer = CInt(cmd.ExecuteScalar())

       If count >= 500 Then
         Goal1.Text = "Congratulations - 500 goal!"
        Else
          Goal1.Text = "Your current score: "& count
        End If

      Catch ex As Exception
         Throw New Exception(ex.Message)
      Finally
         conn.Close()
      End Try
  End Sub
End Class