I'm adding error handling to code that I know works and am encountering a rather odd error in doing so (at least it is odd to me.) Note the following codeNow, I throw in some error handlingCode:'code above this that works fine Dim da As New System.Data.SqlClient.SqlDataAdapter(sSQL, myConnection) da.Fill(ds) Dim rowcount As Integer = ds.Tables.Item(0).Rows.Count 'now, for the display, we need to use the datareader Dim command As New SqlCommand(sSQL, myConnection) Dim reader As SqlDataReader = command.ExecuteReader() 'code below this that also works fine.Now, with the error handing, I'm getting two errors I never had before:Code:'code above this that works fine Try Dim da As New System.Data.SqlClient.SqlDataAdapter(sSQL, myConnection) da.Fill(ds) Dim rowcount As Integer = ds.Tables.Item(0).Rows.Count 'now, for the display, we need to use the datareader Dim command As New SqlCommand(sSQL, myConnection) Dim reader As SqlDataReader = command.ExecuteReader() Catch ex As Exception MessageBox.Show(ex.Message & " " & ex.Source) End Try 'code below this that also works fine
1. Name 'rowcount' is not declared
2. Name 'reader' is not declared
Huh? I can't declare something after a Try?
![]()




Huh? I can't declare something after a Try?
Reply With Quote