here a piece of vb code where i have a problem:

        If G_ObjConnectionTemp.State = ConnectionState.Closed Then
            G_ObjConnectionTemp.Open()
        End If
        ' at this stage the connection is verified to be open
        Dim Obj_CommandF As New OleDbCommand("delete from ficheclient", G_ObjConnectionTemp)
        Using G_ObjConnectionTemp
            Obj_CommandF.ExecuteNonQuery()
        End Using
        Dim xx = G_ObjConnectionTemp.State.ToString
       ' at this stage however the connection is found to be closed Why?

Recommended Answers

The Using statement will close and dispose the object when it reaches the end of the using block.

Jump to Post

All 2 Replies

The Using statement will close and dispose the object when it reaches the end of the using block.

You should just call

Obj_CommandF.ExecuteNonQuery() 

Without the using statement. It is not needed.

Also a note is that the command given has no qualifiers therefore will clear the whole table.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.