Y
Y
Ytsu Ytsuevich2015-01-30 21:15:38
Database
Ytsu Ytsuevich, 2015-01-30 21:15:38

C#. When to use using (in db)?

using (SqlConnection con = new SqlConnection())
{
     SqlCommand cmd = con.CreateCommand();

     cmd.CommandText = "SELECT * FROM Tab";

     using (SqlDataReader reader = cmd.ExecuteReader())
     {
          // reading...
     }
}

And also SqlCommand has a Dispose method , which means I can wrap cmd in using . Do I need to do all this? Or is it enough to put using on one thing???

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question