Exemplo n.º 1
0
        /// <summary>
        /// Select data from database
        /// </summary>
        /// <param name="commandText"></param>
        /// <returns></returns>
        public DataTable SelectData(string commandText)
        {
            try
            {
                using (var connection = _database.CreateConnection())
                {
                    connection.Open();

                    using (var command = _database.CreateCommand(commandText, CommandType.Text, connection))
                    {
                        var dataset    = new DataSet();
                        var dataAdaper = _database.CreateAdapter(command);
                        dataAdaper.Fill(dataset);
                        CloseConnection(connection);
                        if (dataset.Tables.Count > 0)
                        {
                            return(dataset.Tables[0]);
                        }
                        else
                        {
                            return(new DataTable());
                        }
                    }
                }
            } catch (SqlException e)
            {
                throw new SqlCommandException(e.Message, commandText);
            }
        }
Exemplo n.º 2
0
        public DataTable GetDataTable(string commandText, CommandType commandType, IDbDataParameter[] parameters = null)
        {
            using (var connection = database.CreateConnection())
            {
                connection.Open();

                using (var command = database.CreateCommand(commandText, commandType, connection))
                {
                    if (parameters != null)
                    {
                        foreach (var parameter in parameters)
                        {
                            command.Parameters.Add(parameter);
                        }
                    }

                    var dataset    = new DataSet();
                    var dataAdaper = database.CreateAdapter(command);
                    dataAdaper.Fill(dataset);

                    return(dataset.Tables[0]);
                }
            }
        }
Exemplo n.º 3
0
 public DbCommand GetCommand(string commandText, CommandType commandType)
 {
     return(database.CreateCommand(commandText, commandType));
 }