which one is better from following options
Is one using statement is enough?
Option 1:
using(SqlConnection con = new SqlConnection(constring))
{
using(SqlCommand cmd = new SqlCommand())
{
.........................
.........................
.........................
}
}
Option 2:
using(SqlConnection con = new SqlConnection(constring))
{
SqlCommand cmd = new SqlCommand();
.........................
.........................
.........................
}
It's generally simplest to follow the rule, "If the type implements IDisposable
then use a using
construct." So I'd go with some form of option 1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With