المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : clearing up oledb command



C# Programming
11-11-2009, 12:00 PM
Hi, If I use a using command that uses a oleDbCommand object, do I need to close the using statement before I return a result?

eg

using (OleDbCommand Command = GetCommandObj("DB1"))
{
Command.CommandText = "";
return Command.ExecuteScalar().ToString();
}

will the above code dispose of the OleDbCommand and release the connection?

or do I need to do somethiong like:

string result = string.Empty;
using (OleDbCommand Command = GetCommandObj("DB1"))
{
Command.CommandText = "";
result = Command.ExecuteScalar().ToString();
}
return result;


also, should I include something like
Command.Connection.Dispose(); within the using statement to release the connection?

Thanks,
Chas