forum

Home / DeveloperSection / Forums / SqlCommand with using statement

SqlCommand with using statement

Anonymous User 1587 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


c# c# 
Updated on 18-Aug-2014
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By