Exemple #1
0
        //public static PagedDataSource GetPagedDatasource(string procedureName, SQLParameterList parameters, int pagesize)
        //{
        //    DataTable data = GetDataTable(procedureName, parameters);

        //    if (data != null)
        //    {
        //        PagedDataSource pagedData = new PagedDataSource();
        //        pagedData.DataSource = data.DefaultView;
        //        pagedData.AllowPaging = true;
        //        pagedData.PageSize = pagesize;

        //        return pagedData;
        //    }
        //    else
        //        return null;

        //}

        public static DataTable GetDataTable(string procedureName, MySQLParameterList parameters)
        {
            DataTable table = new DataTable();

            MySqlDataAdapter dataAdapter = null;

            MySqlCommand    command    = null;
            MySqlConnection connection = new MySqlConnection(_connectionString);

            try
            {
                connection.Open();
                command             = new MySqlCommand(procedureName, connection);
                command.CommandType = CommandType.StoredProcedure;

                foreach (MySqlParameter parameter in parameters)
                {
                    command.Parameters.Add(parameter);
                }

                dataAdapter = new MySqlDataAdapter(command);

                dataAdapter.Fill(table);

                return(table);
            }
            catch
            {
                return(null);
            }
            finally
            {
                connection.Dispose();
            }
        }
Exemple #2
0
        public static MySqlDataReader GetDataReader(string procedureName, MySQLParameterList parameters)
        {
            MySqlDataReader reader     = null;
            MySqlCommand    command    = null;
            MySqlConnection connection = new MySqlConnection(_connectionString);


            try
            {
                connection.Open();
                command             = new MySqlCommand(procedureName, connection);
                command.CommandType = CommandType.StoredProcedure;
                foreach (MySqlParameter parameter in parameters)
                {
                    command.Parameters.Add(parameter);
                }

                reader = command.ExecuteReader(CommandBehavior.CloseConnection);

                return(reader);
            }
            catch (Exception ex)
            {
                connection.Dispose();
                if (reader != null)
                {
                    reader.Dispose();
                }
                throw ex;
                return(null);
            }
        }
Exemple #3
0
        public static object ExecuteScalar(string procedureName, MySQLParameterList parameters)
        {
            MySqlCommand    command    = null;
            MySqlConnection connection = new MySqlConnection(_connectionString);

            try
            {
                connection.Open();
                command             = new MySqlCommand(procedureName, connection);
                command.CommandType = CommandType.StoredProcedure;
                foreach (MySqlParameter parameter in parameters)
                {
                    command.Parameters.Add(parameter);
                }

                return(command.ExecuteScalar());
            }
            catch (MySqlException ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                if (connection != null)
                {
                    connection.Dispose();
                }
            }
        }
Exemple #4
0
        public static DataSet GetDataSet(string procedureName, MySQLParameterList parameters)
        {
            DataSet          dataSet     = new DataSet();
            MySqlDataAdapter dataAdapter = null;

            MySqlCommand    command    = null;
            MySqlConnection connection = new MySqlConnection(_connectionString);

            try
            {
                connection.Open();
                command             = new MySqlCommand(procedureName, connection);
                command.CommandType = CommandType.StoredProcedure;

                foreach (MySqlParameter parameter in parameters)
                {
                    command.Parameters.Add(parameter);
                }

                dataAdapter = new MySqlDataAdapter(command);

                dataAdapter.Fill(dataSet);

                return(dataSet);
            }
            catch (Exception ex)
            {
                return(null);
                //Need to watch out for catching errors here (lets log it at some point)
                //for instance any errors in Pete's CLR's
            }
            finally
            {
                connection.Dispose();
            }
        }