18
It is correct to use a block using
inside another block using
as in the example below? or 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;
}
}
}
}
}
Thank you for the answer, programming in a certain way is easy the difficult for me often is to be sure that what I am doing is being done in the correct and clean way and in this case your answer left well clarified not to err more.
– Mauricio Ferraz
That’s why we’re here.
– Maniero
@Maniero, enlightening and objective answer. Very good.
– Diego Farias