Example #1
0
        public bool AddDown(Model.T_Count model)
        {
            //读取配置文件中的相关节点信息:数据库连接字符串
            string setting = ConfigurationManager.ConnectionStrings["connstring"].ToString();
            //创建数据库对象
            SqlConnection myconn = new SqlConnection(setting);

            //打开连接
            myconn.Open();
            //创建命令对象,并准备好操作数据库的SQL语句
            SqlCommand cmd = new SqlCommand("insert into T_Count([DownSum],) values (@downsum) where Id=@id", myconn);

            //为SQL语句匹配相关参数,并赋值
            cmd.Parameters.AddWithValue("@id", model.Id);
            cmd.Parameters.AddWithValue("@downsum", model.DownSum);

            //执行相关SQL语句并返回受影响的行数,若受影响行数大于0,则表示执行成功,否者,执行失败
            if (cmd.ExecuteNonQuery() > 0)
            {
                cmd.Dispose();
                myconn.Dispose();
                return(true);
            }
            else
            {
                cmd.Dispose();
                myconn.Dispose();
                return(false);
            }
        }
Example #2
0
        //更新试听数
        #region 修改

        public bool Update(Model.T_Count model)
        {
            //读取配置文件中的相关节点信息:数据库连接字符串
            string setting = ConfigurationManager.ConnectionStrings["connstring"].ToString();

            SqlConnection myconn = new SqlConnection(setting);

            myconn.Open();

            SqlCommand cmd = new SqlCommand("update T_Count set ListenedSum=ListenedSum+1 where Id=@id", myconn);

            cmd.Parameters.AddWithValue("@id", model.Id);
            if (cmd.ExecuteNonQuery() > 0)
            {
                cmd.Dispose();
                myconn.Dispose();

                return(true);
            }
            else
            {
                cmd.Dispose();
                myconn.Dispose();

                return(false);
            }
        }
 private void AddListened()
 {
     //int i = Convert.ToInt32(Request["Id"]);
     Model.T_Count Count = new Model.T_Count();
     Count.Id = i;
     BLL.T_Count CountBll = new BLL.T_Count();
     if (CountBll.Update(Count))
     {
     }
 }