Exemple #1
0
 /// <summary>
 /// 参数准备
 /// </summary>
 /// <returns></returns>
 public static SqlCommand ParameterElse(SqlCommand cmd, ORM.Test.LinkAndCategory LinkAndCategory_obj)
 {
     cmd.Parameters.AddWithValue("@CID", LinkAndCategory_obj.CID);
     cmd.Parameters["@CID"].SqlDbType = System.Data.SqlDbType.Int;
     cmd.Parameters.AddWithValue("@LID", LinkAndCategory_obj.LID);
     cmd.Parameters["@LID"].SqlDbType = System.Data.SqlDbType.Int;
     return(cmd);
 }
Exemple #2
0
        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="LinkAndCategory_obj"></param>
        /// <param name="IsRowLock">是否锁行</param>
        /// <returns></returns>
        public static int Update(ORM.Test.LinkAndCategory LinkAndCategory_obj, bool IsRowLock)
        {
            StringBuilder sqlSet   = new StringBuilder();
            StringBuilder sqlWhere = new StringBuilder();
            string        sql      = string.Empty;

            if (IsRowLock)
            {
                sql = "UPDATE LinkAndCategory WITH(ROWLOCK) SET {0} WHERE {1}";
            }
            else
            {
                sql = "UPDATE LinkAndCategory SET {0} WHERE {1}";
            }
            SqlCommand cmd = new SqlCommand();

            cmd.Parameters.AddWithValue("@ID", LinkAndCategory_obj.ID);
            cmd.Parameters["@ID"].SqlDbType = System.Data.SqlDbType.Int;
            if (sqlWhere.Length == 0)
            {
                sqlWhere.Append("[ID]=@ID");
            }
            else
            {
                sqlWhere.Append(" AND [ID]=@ID");
            }
            cmd.Parameters.AddWithValue("@CID", LinkAndCategory_obj.CID);
            cmd.Parameters["@CID"].SqlDbType = System.Data.SqlDbType.Int;
            if (sqlSet.Length == 0)
            {
                sqlSet.Append("[CID=@CID");
            }
            else
            {
                sqlSet.Append(",[CID=@CID");
            }
            cmd.Parameters.AddWithValue("@LID", LinkAndCategory_obj.LID);
            cmd.Parameters["@LID"].SqlDbType = System.Data.SqlDbType.Int;
            if (sqlSet.Length == 0)
            {
                sqlSet.Append("[LID=@LID");
            }
            else
            {
                sqlSet.Append(",[LID=@LID");
            }
            sql             = string.Format(sql, sqlSet.ToString(), sqlWhere.ToString());
            cmd.CommandText = sql;
            try
            {
                return(new ORM.DBUtility.DBHelper(true).ExecNonQuery(cmd));
            }
            catch { return(-1); }
        }
Exemple #3
0
        /// <summary>
        /// 插入数据,返回自增列ID
        /// </summary>
        /// <returns></returns>
        public static bool Add(ORM.Test.LinkAndCategory LinkAndCategory_obj, out Int32 ID)
        {
            ID = 0;
            StringBuilder cols       = new StringBuilder();
            StringBuilder parameters = new StringBuilder();
            string        sql        = "INSERT INTO LinkAndCategory({0}) values({1});SELECT @@IDENTITY;";

            if (cols.Length > 0)
            {
                cols.Append(",[CID]");
                parameters.Append(",@CID");
            }
            else
            {
                cols.Append("[CID]");
                parameters.Append("@CID");
            }
            if (cols.Length > 0)
            {
                cols.Append(",[LID]");
                parameters.Append(",@LID");
            }
            else
            {
                cols.Append("[LID]");
                parameters.Append("@LID");
            }
            sql = string.Format(sql, cols.ToString(), parameters.ToString());
            SqlCommand cmd = new SqlCommand(sql);

            cmd = ParameterElse(cmd, LinkAndCategory_obj);
            bool b = true;

            try
            {
                object idobj = new ORM.DBUtility.DBHelper(true).ExecScalar(cmd);
                ID = Convert.ToInt32(idobj);
                if (ID == 0)
                {
                    b = false;
                }
            }
            catch { b = false; }
            return(b);
        }
Exemple #4
0
        /// <summary>
        /// 插入数据
        /// </summary>
        /// <returns></returns>
        public static bool insert(ORM.Test.LinkAndCategory LinkAndCategory_obj)
        {
            StringBuilder cols       = new StringBuilder();
            StringBuilder parameters = new StringBuilder();
            string        sql        = "INSERT INTO LinkAndCategory({0}) values({1})";

            if (cols.Length > 0)
            {
                cols.Append(",[CID]");
                parameters.Append(",@CID");
            }
            else
            {
                cols.Append("[CID]");
                parameters.Append("@CID");
            }
            if (cols.Length > 0)
            {
                cols.Append(",[LID]");
                parameters.Append(",@LID");
            }
            else
            {
                cols.Append("[LID]");
                parameters.Append("@LID");
            }
            sql = string.Format(sql, cols.ToString(), parameters.ToString());
            SqlCommand cmd = new SqlCommand(sql);

            cmd = ParameterElse(cmd, LinkAndCategory_obj);
            bool b = true;

            try
            {
                int QueryCount = new ORM.DBUtility.DBHelper(true).ExecNonQuery(cmd);
                if (QueryCount != 1)
                {
                    b = false;
                }
            }
            catch { b = false; }
            return(b);
        }