0

when comboxbox selects "NOINV" for which there is no value then an error appears how can I bypass the error.

Thanks

  Private Sub DisTotal()
            Dim query As String = "SELECT (DIS/BLC)*100 FROM RSG WHERE NOINV=@NOINV"
            Try
                Using con As OleDbConnection = New OleDbConnection(GetConnectionString)
                    con.Open()
                    Using cmd As OleDbCommand = New OleDbCommand(query, con)
                        cmd.Parameters.AddWithValue("@NOINV", ComboBox1.SelectedValue)
                        Dim DisTotal As Double = Double.Parse(lblDisTotal.Text)
'ERROR THIS BELOW LINE CODE
                        DisTotal = CDbl(cmd.ExecuteScalar().ToString())
                    End Using
                End Using
            Catch myerror As OleDbException
                MessageBox.Show("Error: " & myerror.Message)
            Finally
            End Try
        End Sub

select combobox blank value

roy
  • 693
  • 2
  • 11
  • The easiest way is to add a check on the value before you call the database. If value is empty then don't make the call. – Julian Jan 16 '23 at 14:12

0 Answers0