What is using?

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!
 
M

Mark Fitzpatrick

Using in this context allows for automatic displosal and garbage collection
of the objects.
 
I

IfThenElse

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,786
Messages
2,569,626
Members
45,328
Latest member
66Teonna9

Latest Threads

Top