Is it correct to use a block using
within another block using
as in the example below? or is it enough to just put the first using
?
public DataTable Listar(string stringMySql, CommandType commandType, List<MySqlParameter> lstParametros)
{
using (MySqlConnection mySqlConnection = new MySqlConnection())
{
mySqlConnection.ConnectionString = StaticKey.RetornaStringConexao();
mySqlConnection.Open();
using (MySqlCommand mySqlCommand = new MySqlCommand())
{
mySqlCommand.Connection = mySqlConnection;
mySqlCommand.CommandType = commandType;
mySqlCommand.CommandText = stringMySql.Trim();
if (lstParametros != null)
{
mySqlCommand.Parameters.AddRange(lstParametros.ToArray());
}
using (DataTable dataTable = new DataTable())
{
using (MySqlDataAdapter mySqlDataAdapter = new MySqlDataAdapter(mySqlCommand))
{
mySqlDataAdapter.Fill(dataTable);
return dataTable;
}
}
}
}
}