I am curious of why I cannot dispose the dataview (dv) as shown in this code block.
I get the blue squiggly line under the dv.Dispose() with a message 'dv' is not declared. It is declared in the Try Catch Block and since I am using the Finally section of that TC Block why don't it recognize the declaration. Also does that mean my other Object disposals are being ignored since they are in the block and the declarations are outside of the block?VB Code:
Private Sub FillMarketingPieceCombo() Dim strSQL As String = _ "Select MarketingPiece From queMarketingPiece" Dim con As New OleDbConnection(strCon) Dim da As OleDbDataAdapter = _ New OleDbDataAdapter(strSQL, con) Dim ds As DataSet = New DataSet Try da.Fill(ds, "MP") Dim dv As DataView = ds.Tables("MP").DefaultView cbMarketing.DataSource = dv cbMarketing.DisplayMember = "MarketingPiece" Catch ex As Exception MessageBox.Show( _ ex.Message & vbNewLine & _ ex.Source, _ "Marketing Piece Error", _ MessageBoxButtons.OK, _ MessageBoxIcon.Error) Finally da.Dispose() ds.Dispose() dv.Dispose() con.Dispose() End Try End Sub




Reply With Quote