Link to home
Start Free TrialLog in
Avatar of indy500fan
indy500fan

asked on

Dealing with a non-existant table...

Friends,

I have a piece of code that, when activated by a timer, selects a set of results from a particular database.  It works great if there are records or not, but if the table doesn't exist, it breaks.  What syntax is required to deal with a returned message of "Invalid object name 'Results'."?  Ultimately, I want to return 0's for my values, but...

Syntax help requested please!

Here is my code:

Public Sub GetCurrentSessionResults(ByVal dsnCurrentRun As String)

        Try

            Dim data As New DataSet
            Dim r As DataRow

            Dim con As New SqlClient.SqlConnection(dsnCurrentRun)

            'fill in the data for a lap ...
            data = New DataSet

            Dim dr As SqlClient.SqlDataReader

            con = New SqlClient.SqlConnection(dsnCurrentRun)

            con.Open()

            Dim c As New SqlClient.SqlCommand("Select Laps = Sum(Laps) from Results", con)

            dr = c.ExecuteReader(CommandBehavior.SingleResult)

            Dim found As Boolean
            Dim cmb As ComboBox

            Dim i As Integer
            found = False
       
            If dr.HasRows Then
                While dr.Read()
                    If dr.IsDBNull(i) Then
                        CurrentSessionLaps = 0
                        lblCurrentSession.Text = CurrentSessionLaps
                    Else
                        CurrentSessionLaps = dr.Item("Laps")
                        lblCurrentSession.Text = CurrentSessionLaps
                    End If
                End While

            End If

                con.Close()
                con = Nothing

        Catch ex As Exception

            MessageBox.Show(ex.Message)

        End Try

    End Sub

Thanks in advance!
ASKER CERTIFIED SOLUTION
Avatar of Sancler
Sancler

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of indy500fan
indy500fan

ASKER

Sancler,

Hmm...I will try it.
Sancler,

Well, that simple suggestion works.

Thanks!