testing try/catch when filling a data adapter

  • Thread starter Thread starter SteveS
  • Start date Start date
S

SteveS

Hello. This may be a dumb question, but it's driving me crazy. The
function is supposed to to fill a datatable. It works just fine, but I'm
testing to make sure my error handling works so I changed the name of the
stored procedure so I know I will get an error. However, for some reason,
my try/catch does not catch the error. Instead, the program seems to stop.
Does this make sense? Do you have any ideas why this happens?

Thank you!



Protected sub Run(ByVal sprocName As String, ByVal parameters() As
SqlParameter, ByRef dataTable As DataTable)

Dim command As SqlCommand

command = CreateCommand(sprocName, parameters)

Dim dataAdapter As SqlDataAdapter

dataTable = New DataTable

dataAdapter = New SqlDataAdapter

dataAdapter.SelectCommand = command

dataAdapter.Fill(dataTable)

End Function
 
SteveS said:
Hello. This may be a dumb question, but it's driving me crazy. The
function is supposed to to fill a datatable. It works just fine, but I'm
testing to make sure my error handling works so I changed the name of the
stored procedure so I know I will get an error. However, for some reason,
my try/catch does not catch the error. Instead, the program seems to stop.
Does this make sense? Do you have any ideas why this happens?

Protected sub Run(ByVal sprocName As String, ByVal parameters() As
SqlParameter, ByRef dataTable As DataTable)

Dim command As SqlCommand
command = CreateCommand(sprocName, parameters)
Dim dataAdapter As SqlDataAdapter
dataTable = New DataTable
dataAdapter = New SqlDataAdapter
dataAdapter.SelectCommand = command
dataAdapter.Fill(dataTable)
End Function

Well for one thing, you haven't shown a try/catch in there...
 
Back
Top