What is using?

  • Thread starter Thread starter Paulo
  • Start date Start date
P

Paulo

using (OleDbConnection connection = new
OleDbConnection(ConfigurationManager.ConnectionStrings["Access"].ConnectionString))
{
using (OleDbCommand command = new OleDbCommand(strSQL, connection))
{
command.CommandType = CommandType.Text;
command.Parameters.Add(new OleDbParameter("@AlbumID", albumid));
command.Parameters.Add(new OleDbParameter("@Size", (int)size));
...
}
}

What is diference? Any performance improvement? I found the code above on a
starter kit

OleDbConnection connection = new
OleDbConnection(ConfigurationManager.ConnectionStrings["Access"].ConnectionString)
OleDbCommand command = new OleDbCommand(strSQL, connection)
command.CommandType = CommandType.Text;
command.Parameters.Add(new OleDbParameter("@AlbumID", albumid));
command.Parameters.Add(new OleDbParameter("@Size", (int)size));
....

VS 2005 asp.net 2.0 C#

Thanks!
 
Using in this context allows for automatic displosal and garbage collection
of the objects.
 
Very good.


George Ter-Saakov said:
http://davidhayden.com/blog/dave/archive/2005/01/13/773.aspx

George

Paulo said:
using (OleDbConnection connection = new
OleDbConnection(ConfigurationManager.ConnectionStrings["Access"].ConnectionString))
{
using (OleDbCommand command = new OleDbCommand(strSQL, connection))
{
command.CommandType = CommandType.Text;
command.Parameters.Add(new OleDbParameter("@AlbumID", albumid));
command.Parameters.Add(new OleDbParameter("@Size", (int)size));
...
}
}

What is diference? Any performance improvement? I found the code above on
a starter kit

OleDbConnection connection = new
OleDbConnection(ConfigurationManager.ConnectionStrings["Access"].ConnectionString)
OleDbCommand command = new OleDbCommand(strSQL, connection)
command.CommandType = CommandType.Text;
command.Parameters.Add(new OleDbParameter("@AlbumID", albumid));
command.Parameters.Add(new OleDbParameter("@Size", (int)size));
...

VS 2005 asp.net 2.0 C#

Thanks!
 
Back
Top