Exemplo n.º 1
0
        public DataTable GetDataTable(string commandText, CommandType type, IDataParameter[] parameters = null)
        {
            using (var connection = database.CreateConnection())
            {
                using (var command = database.CreateCommand(commandText, type, connection))
                {
                    if (parameters != null)
                    {
                        foreach (IDataParameter parameter in parameters)
                        {
                            command.Parameters.Add(parameter);
                        }
                    }

                    var dataset     = new DataSet();
                    var dataAdapter = database.CreateDataAdapter(command);
                    dataAdapter.Fill(dataset);
                    return(dataset.Tables[0]);
                }
            }
        }