Better way of using SqlCommand

Just came accross this following snippet.

using(SqlConnection conn = new SqlConnection)

{

conn.Open();

SqlCommand cmd= new SqlCommand();

cmd.ExecuteNonQuery();

conn.Close()

}

It's always better off cosing this inside a using block , bcoz what is the command thows an exception. Inside the using block the object wil always be disposed .

 

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
Print | posted on Saturday, June 17, 2006 2:41 AM

Feedback

No comments posted yet.
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: