Users Pricing

forum

Home Forums SqlCommand with using statement – MindStick

SqlCommand with using statement

Anonymous User 1943 18 Aug 2014

I saw that in most samples SqlCommand was used like this

using (SqlConnection con = new SqlConnection(CNN_STRING))
{
    using (SqlCommand cmd = new SqlCommand("Select ID,Name From Person", con))
    {
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds =new DataSet();
        da.Fill(ds);          
        return ds;
    }
}

I know why we are using "using" statement. But SqlCommand doesn't inlcude Close() method, so should we really use it within using statement


1 Answers

Markdown for AI

A clean, structured version of this page for AI assistants and LLMs.

Open .md