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(B yVal dsnCurrentRun As String)
Try
Dim data As New DataSet
Dim r As DataRow
Dim con As New SqlClient.SqlConnection(ds nCurrentRu n)
'fill in the data for a lap ...
data = New DataSet
Dim dr As SqlClient.SqlDataReader
con = New SqlClient.SqlConnection(ds nCurrentRu n)
con.Open()
Dim c As New SqlClient.SqlCommand("Sele ct Laps = Sum(Laps) from Results", con)
dr = c.ExecuteReader(CommandBeh avior.Sing leResult)
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!
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(B
Try
Dim data As New DataSet
Dim r As DataRow
Dim con As New SqlClient.SqlConnection(ds
'fill in the data for a lap ...
data = New DataSet
Dim dr As SqlClient.SqlDataReader
con = New SqlClient.SqlConnection(ds
con.Open()
Dim c As New SqlClient.SqlCommand("Sele
dr = c.ExecuteReader(CommandBeh
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Sancler,
Well, that simple suggestion works.
Thanks!
Well, that simple suggestion works.
Thanks!
ASKER
Hmm...I will try it.