Exemple #1
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int update(Model.test model)
        {
            string strSql = "UPDATE test SET Password=@Password,Name=@Name WHERE Id=@Id";

            MySqlParameter[] parameters =
            {
                new MySqlParameter("@Password", MySqlDbType.VarChar, 255),
                new MySqlParameter("@Name",     MySqlDbType.VarChar, 255),
                new MySqlParameter("@Id",       MySqlDbType.Int32)
            };

            parameters[0].Value = model.Password;
            parameters[1].Value = model.Name;
            parameters[2].Value = model.ID;

            object obj = Utility.MySqlHelper.ExecuteTxtScalar(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Exemple #2
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int add(Model.test model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into test(");
            strSql.Append("Password,Name)");
            strSql.Append(" values (");
            strSql.Append("@Password,@Name)");
            strSql.Append(";select @@IDENTITY");
            MySqlParameter[] parameters =
            {
                new MySqlParameter("@Password", MySqlDbType.VarChar, 255),
                new MySqlParameter("@Name",     MySqlDbType.VarChar, 255),
            };
            parameters[0].Value = model.Password;
            parameters[1].Value = model.Name;

            object obj = Utility.MySqlHelper.ExecuteTxtScalar(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }