Hello MikeJ,
Using in .Net is just like try catch and finally block. Like when we make connection with sql server then connection should be open in try block and we close the connection in finally block.
But when we used using statement then no need to close the connection when connection object goes out of scope then it dispose connection automatically.
Example 1:
using(SqlConnection cn = new SqlConnection(ConfigurationManager.
ConnectionStrings
["MyConnection"].ConnectionString))
using(SqlCommand cmd = cn.CreateCommand())
using(SqlDataAdapter sda = new SqlDataAdapter())
{
cn.Open();
/* code that actually does stuff */
}
Example 2:
Connection c;
try
{ c = new Connection(...);
}
finally
{ c.Close();
}
Thanks
pavan