I have written 6 Queries in an Access DB, which are executed in a For
Each…Next loop to populate DataSet object. A new DataTable object is created
in DataSet for each query, as follows
Private Sub GetRawLiRatios( )
Dim cnn As OleDbConnection
Dim cmd As New OleDbCommand
Dim dad As OleDbDataAdapte r
Dim dstRawFigures As New DataSet
Dim arrRatios As String() = [Enum].GetNames(GetTy pe(LiRatios))
Dim obj As New DataStructureCo nverter
Try
'! Initialize OleDbConnection object.
cnn = CreateConnectio n()
'! Set connection property for OleDbCommand object.
cmd.Connection = cnn
'! Add parameters to the paramter collection.
cmd.Parameters. Add("IndustryNa me", cboIndustry.Tex t)
cmd.Parameters. Add("Year", nudYear.Value)
'! Set the command type property of the command object.
cmd.CommandType = CommandType.Sto redProcedure
For Each ratio As String In arrRatios
'! Set the command text property of the command object
'! to the name of the query.
cmd.CommandText = ratio
'! Initialize data adapter object with command object.
dad = New OleDbDataAdapte r(cmd)
'! Fill the dataset.
dad.Fill(dstRaw Figures, ratio)
Next ratio
Catch ioExcep As IO.IOException
MessageBox.Show (ioExcep.Messag e, Application.Pro ductName,
MessageBoxButto ns.OK, MessageBoxIcon. Error)
Catch ex As Exception
Call HandleException (Me.Name, ex, "GetRawLiRatios ")
End Try
End Sub
Where arrRatios is an Enumeration which contains name of the queries in
access db. If any of the queries get deleted from the access db, For
Each...Next loop is exited and exception is thrown.
Now I want my For Each...Next loop to continue processing for reaming
queries in the db, rather than throwing an exception. How can I check whether
queries exists in the db before using Fill method?
Thanks
Each…Next loop to populate DataSet object. A new DataTable object is created
in DataSet for each query, as follows
Private Sub GetRawLiRatios( )
Dim cnn As OleDbConnection
Dim cmd As New OleDbCommand
Dim dad As OleDbDataAdapte r
Dim dstRawFigures As New DataSet
Dim arrRatios As String() = [Enum].GetNames(GetTy pe(LiRatios))
Dim obj As New DataStructureCo nverter
Try
'! Initialize OleDbConnection object.
cnn = CreateConnectio n()
'! Set connection property for OleDbCommand object.
cmd.Connection = cnn
'! Add parameters to the paramter collection.
cmd.Parameters. Add("IndustryNa me", cboIndustry.Tex t)
cmd.Parameters. Add("Year", nudYear.Value)
'! Set the command type property of the command object.
cmd.CommandType = CommandType.Sto redProcedure
For Each ratio As String In arrRatios
'! Set the command text property of the command object
'! to the name of the query.
cmd.CommandText = ratio
'! Initialize data adapter object with command object.
dad = New OleDbDataAdapte r(cmd)
'! Fill the dataset.
dad.Fill(dstRaw Figures, ratio)
Next ratio
Catch ioExcep As IO.IOException
MessageBox.Show (ioExcep.Messag e, Application.Pro ductName,
MessageBoxButto ns.OK, MessageBoxIcon. Error)
Catch ex As Exception
Call HandleException (Me.Name, ex, "GetRawLiRatios ")
End Try
End Sub
Where arrRatios is an Enumeration which contains name of the queries in
access db. If any of the queries get deleted from the access db, For
Each...Next loop is exited and exception is thrown.
Now I want my For Each...Next loop to continue processing for reaming
queries in the db, rather than throwing an exception. How can I check whether
queries exists in the db before using Fill method?
Thanks
Comment