Esempio n. 1
0
        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="LinkCategory_obj"></param>
        /// <param name="IsRowLock">是否锁行</param>
        /// <returns></returns>
        public static int Update(ORM.Test.LinkCategory LinkCategory_obj, bool IsRowLock)
        {
            StringBuilder sqlSet   = new StringBuilder();
            StringBuilder sqlWhere = new StringBuilder();
            string        sql      = string.Empty;

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

            cmd.Parameters.AddWithValue("@ID", LinkCategory_obj.ID);
            cmd.Parameters["@ID"].SqlDbType = System.Data.SqlDbType.Int;
            if (sqlWhere.Length == 0)
            {
                sqlWhere.Append("[ID]=@ID");
            }
            else
            {
                sqlWhere.Append(" AND [ID]=@ID");
            }
            if (LinkCategory_obj.Category != null)
            {
                cmd.Parameters.AddWithValue("@Category", LinkCategory_obj.Category);
                cmd.Parameters["@Category"].SqlDbType = System.Data.SqlDbType.NVarChar;
                if (sqlSet.Length == 0)
                {
                    sqlSet.Append("[Category]=@Category");
                }
                else
                {
                    sqlSet.Append(",[Category]=@Category");
                }
            }
            if (LinkCategory_obj.Description != null)
            {
                cmd.Parameters.AddWithValue("@Description", LinkCategory_obj.Description);
                cmd.Parameters["@Description"].SqlDbType = System.Data.SqlDbType.NVarChar;
                if (sqlSet.Length == 0)
                {
                    sqlSet.Append("[Description]=@Description");
                }
                else
                {
                    sqlSet.Append(",[Description]=@Description");
                }
            }
            sql             = string.Format(sql, sqlSet.ToString(), sqlWhere.ToString());
            cmd.CommandText = sql;
            try
            {
                return(new ORM.DBUtility.DBHelper(true).ExecNonQuery(cmd));
            }
            catch { return(-1); }
        }
Esempio n. 2
0
 /// <summary>
 /// 参数准备
 /// </summary>
 /// <returns></returns>
 public static SqlCommand ParameterElse(SqlCommand cmd, ORM.Test.LinkCategory LinkCategory_obj)
 {
     if (LinkCategory_obj.Category != null)
     {
         cmd.Parameters.AddWithValue("@Category", LinkCategory_obj.Category);
         cmd.Parameters["@Category"].SqlDbType = System.Data.SqlDbType.NVarChar;
     }
     if (LinkCategory_obj.Description != null)
     {
         cmd.Parameters.AddWithValue("@Description", LinkCategory_obj.Description);
         cmd.Parameters["@Description"].SqlDbType = System.Data.SqlDbType.NVarChar;
     }
     return(cmd);
 }
Esempio n. 3
0
        /// <summary>
        /// 插入数据,返回自增列ID
        /// </summary>
        /// <returns></returns>
        public static bool Add(ORM.Test.LinkCategory LinkCategory_obj, out Int32 ID)
        {
            ID = 0;
            StringBuilder cols       = new StringBuilder();
            StringBuilder parameters = new StringBuilder();
            string        sql        = "INSERT INTO LinkCategory({0}) values({1});SELECT @@IDENTITY;";

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

            cmd = ParameterElse(cmd, LinkCategory_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);
        }
Esempio n. 4
0
        /// <summary>
        /// 插入数据
        /// </summary>
        /// <returns></returns>
        public static bool insert(ORM.Test.LinkCategory LinkCategory_obj)
        {
            StringBuilder cols       = new StringBuilder();
            StringBuilder parameters = new StringBuilder();
            string        sql        = "INSERT INTO LinkCategory({0}) values({1})";

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

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

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