i have the following code which works fine where there is data in the table.

when the table is empty and there is no data in the @Ctotal varible i get my error

MessageBox.Show("Unable to get Claim Total")


is there anyway i can ignore this if there isn't a value in the @ctotal?

Private Sub Gettotal()
        Dim con As New SqlConnection
        Dim cmd As New SqlCommand
        Try
            con.ConnectionString = "Data Source=" & ServerV & ";Initial Catalog=" & databaseV & ";Persist Security Info=True;User ID=" & usernameV & ";Password=" & passwordV & ""
            con.Open()
            cmd.Connection = con
            cmd.CommandText = "ClaimTotal"
            cmd.CommandType = CommandType.StoredProcedure

            Dim number1Param As New SqlParameter("@Ctotal", SqlDbType.Money, 4)
            number1Param.Direction = ParameterDirection.Output
            cmd.Parameters.Add(number1Param)

            Dim reader As SqlDataReader = cmd.ExecuteReader()

            Me.lbtotal.Text = Convert.ToDouble(number1Param.Value)
        Catch ex As Exception

            MessageBox.Show("Unable to get Claim Total")
        Finally
            con.Close()
        End Try

    End Sub

Recommended Answers

All 4 Replies

You need to check for and handle NULL values in your Stored Procedure.

how would i do this?

i do not know if i am right, i normally add an isnull into a query, but i beleive in .net it is

if string.isnullorempty 
do what if it is nothing
else
do what if it is something
end if

that could be wrong though.

Member Avatar for Unhnd_Exception
if number1param.value is dbnull.value then
  lbltotal.text = "0"
else
  lbltotal.text = cdbl(number1param.value).tostring
endif
commented: thanks, i wasnt positive +3
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.