Example #1
0
        /// <summary>
        /// Used to get the data from the database into tabular form.
        /// </summary>
        /// <param name="query">Query command to fetch the data</param>
        /// <param name="type">Type of the command</param>
        /// <param name="parameters">Parameters if required</param>
        /// <returns>Iterative Dataset</returns>

        protected IEnumerable <IDataRecord> GetIteratableData(string query, SQLCommandTypes type, params SqlParameter[] parameters)
        {
            if (type == SQLCommandTypes.StoredProcedure)
            {
                SqlCommand command = new SqlCommand(query, dbConnection)
                {
                    CommandType = CommandType.StoredProcedure
                };
                command.Parameters.AddRange(parameters);
                dbConnection.Open();
                using (var reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        yield return(reader);
                    }
                }
                dbConnection.Close();
            }
            else
            {
                SqlCommand command = new SqlCommand(query, dbConnection);
                dbConnection.Open();
                using (var reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        yield return(reader);
                    }
                }
                dbConnection.Close();
            }
        }
Example #2
0
 /// <summary>
 /// Used to execute query.
 /// </summary>
 /// <param name="query">Query command to fetch the data</param>
 /// <param name="type">Type of the command</param>
 /// <param name="parameters">Parameters if required</param>
 protected void ExecuteQuery(string query, SQLCommandTypes type, params SqlParameter[] parameters)
 {
     if (type == SQLCommandTypes.StoredProcedure)
     {
         SqlCommand command = new SqlCommand(query, dbConnection)
         {
             CommandType = CommandType.StoredProcedure
         };
         command.Parameters.AddRange(parameters);
         dbConnection.Open();
         try
         {
             command.ExecuteNonQuery();
         }
         catch (SqlException)
         {
             throw;
         }
         dbConnection.Close();
     }
     else
     {
         SqlCommand command = new SqlCommand(query, dbConnection);
         dbConnection.Open();
         try
         {
             command.ExecuteNonQuery();
         }
         catch (SqlException)
         {
             throw;
         }
         dbConnection.Close();
     }
 }
Example #3
0
        private string GetCmdText(SQLCommandTypes cmdtype, string db, string table)
        {
            if (_cmdCache == null)
            {
                LoadCache();
            }

            var ret = _cmdCache.ContainsKey(cmdtype) ? _cmdCache[cmdtype].CreateCmd(db, table) : null;

            CmdBuilder.Append(ret);
            return(ret);
        }
Example #4
0
        /// <summary>
        /// Used to get the data from the database as a single value.
        /// </summary>
        /// <param name="query">Query command to fetch the data</param>
        /// <param name="type">Type of the command</param>
        /// <param name="parameters">Parameters if required</param>
        /// <returns>Single Object Value</returns>
        protected object GetValue(string query, SQLCommandTypes type, params SqlParameter[] parameters)
        {
            object value;

            if (type == SQLCommandTypes.StoredProcedure)
            {
                SqlCommand command = new SqlCommand(query, dbConnection)
                {
                    CommandType = CommandType.StoredProcedure
                };
                command.Parameters.AddRange(parameters);
                dbConnection.Open();
                try
                {
                    value = command.ExecuteScalar();
                }
                catch (SqlException)
                {
                    throw;
                }
                dbConnection.Close();
            }
            else
            {
                SqlCommand command = new SqlCommand(query, dbConnection);
                dbConnection.Open();
                try
                {
                    value = command.ExecuteScalar();
                }
                catch (SqlException)
                {
                    throw;
                }
                dbConnection.Close();
            }
            return(value);
        }
Example #5
0
        /// <summary>
        /// Used to get the data from the database into tabular form.
        /// </summary>
        /// <param name="query">Query command to fetch the data</param>
        /// <param name="type">Type of the command</param>
        /// <param name="parameters">Parameters if required</param>
        /// <returns>Iterative Dataset</returns>
        protected SqlDataReader GetIteratableData(string query, SQLCommandTypes type, params SqlParameter[] parameters)
        {
            SqlDataReader data;

            if (type == SQLCommandTypes.StoredProcedure)
            {
                SqlCommand command = new SqlCommand(query, dbConnection);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddRange(parameters);
                dbConnection.Open();
                try
                {
                    data = command.ExecuteReader();
                }
                catch (SqlException)
                {
                    throw;
                }
                dbConnection.Close();
            }
            else
            {
                SqlCommand command = new SqlCommand(query, dbConnection);
                dbConnection.Open();
                try
                {
                    data = command.ExecuteReader();
                }
                catch (SqlException)
                {
                    throw;
                }
                dbConnection.Close();
            }
            return(data);
        }
Example #6
0
 public SQLCmd(DbConnection connection, SQLCommandTypes cmdtype)
 {
     Connection = connection;
     cmdTpye    = cmdtype;
     _builder   = new MySQLCommandBuilder(cmdTpye, _db, _table);
 }
Example #7
0
 public MySQLCommandBuilder(SQLCommandTypes cmdtype, string db, string table)
 {
     SQLCmdType = cmdtype;
     GetCmdText(cmdtype, db, table);
 }