Exemplo n.º 1
0
        private static SqlCommand BuildIntCommand(SqlConnection connection, string storedProcName, IDataParameter[] parameters)
        {
            SqlCommand command = DbHelperSQL2.BuildQueryCommand(connection, storedProcName, parameters);

            command.Parameters.Add(new SqlParameter("ReturnValue", SqlDbType.Int, 4, ParameterDirection.ReturnValue, false, 0, 0, string.Empty, DataRowVersion.Default, null));
            return(command);
        }
Exemplo n.º 2
0
        public static void ExecuteSqlTran(Hashtable SQLStringList)
        {
            Database db = DatabaseFactory.CreateDatabase();

            using (DbConnection dbconn = db.CreateConnection())
            {
                dbconn.Open();
                DbTransaction dbtran = dbconn.BeginTransaction();
                try
                {
                    foreach (object obj in SQLStringList)
                    {
                        DictionaryEntry myDE     = (DictionaryEntry)obj;
                        string          strsql   = myDE.Key.ToString();
                        SqlParameter[]  cmdParms = (SqlParameter[])myDE.Value;
                        if (strsql.Trim().Length > 1)
                        {
                            DbCommand dbCommand = db.GetSqlStringCommand(strsql);
                            DbHelperSQL2.BuildDBParameter(db, dbCommand, cmdParms);
                            db.ExecuteNonQuery(dbCommand);
                        }
                    }
                    dbtran.Commit();
                }
                catch
                {
                    dbtran.Rollback();
                }
                finally
                {
                    dbconn.Close();
                }
            }
        }
Exemplo n.º 3
0
        public static DataSet Query(string strSql, params SqlParameter[] cmdParms)
        {
            Database  db        = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql);

            DbHelperSQL2.BuildDBParameter(db, dbCommand, cmdParms);
            return(db.ExecuteDataSet(dbCommand));
        }
Exemplo n.º 4
0
        public static object RunProcedure(string storedProcName, IDataParameter[] InParameters, SqlParameter OutParameter, int rowsAffected)
        {
            Database  db        = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetStoredProcCommand(storedProcName);

            DbHelperSQL2.BuildDBParameter(db, dbCommand, (SqlParameter[])InParameters);
            db.AddOutParameter(dbCommand, OutParameter.ParameterName, OutParameter.DbType, OutParameter.Size);
            rowsAffected = db.ExecuteNonQuery(dbCommand);
            return(db.GetParameterValue(dbCommand, "@" + OutParameter.ParameterName));
        }
Exemplo n.º 5
0
        public static bool Exists(string strSql, params SqlParameter[] cmdParms)
        {
            Database  db        = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql);

            DbHelperSQL2.BuildDBParameter(db, dbCommand, cmdParms);
            object obj = db.ExecuteScalar(dbCommand);
            int    cmdresult;

            if (object.Equals(obj, null) || object.Equals(obj, DBNull.Value))
            {
                cmdresult = 0;
            }
            else
            {
                cmdresult = int.Parse(obj.ToString());
            }
            return(cmdresult != 0);
        }
Exemplo n.º 6
0
        public static object GetSingle(string strSql, params SqlParameter[] cmdParms)
        {
            Database  db        = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql);

            DbHelperSQL2.BuildDBParameter(db, dbCommand, cmdParms);
            object obj = db.ExecuteScalar(dbCommand);
            object result;

            if (object.Equals(obj, null) || object.Equals(obj, DBNull.Value))
            {
                result = null;
            }
            else
            {
                result = obj;
            }
            return(result);
        }