Beispiel #1
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);

                    command.Parameters.Clear();
                    //parameters.
                    return(dataset.Tables[0]);
                }
            }
        }
Beispiel #2
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);
            }
        }
 public DataTable GetDataTable(string commandText, CommandType commandType, int commandTimeout, List <IDbDataParameter> parameters = null)
 {
     using (var connection = _database.CreateConnection())
     {
         connection.Open();
         using (var command = _database.CreateCommand(commandText, commandType, connection, commandTimeout))
         {
             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]);
         }
     }
 }