As usual a disposable object (OdbcConnection
) should be disposed when you don't need it anymore.
The using statement will be very helpful in this scenario
DataSet ds = new DataSet();
using(OdbcConnection conn = new OdbcConnection(connectionString))
{
conn.Open(); // Open the connection
string strQuery = "SELECT * FROM ISPINMAS";
var adapter = new OdbcDataAdapter(strQuery, conn);
adapter.Fill(ds);
}
// At this point the connection is closed and dispose has been called to
// free the resources used by the connection
DataTable dt = ds.Tables[0];
dataGridView1.DataSource = dt.DefaultView;
// No need to close the connection here
Also note that I have removed from your code the try/catch because you are not trying to handle anything there. You have just closed the connection, but the using statement will ensure that also in case of exceptions.