コード例 #1
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(StudentMS.Model.Course model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update Course set ");
            strSql.Append("CName=@CName,");
            strSql.Append("Credit=@Credit,");
            strSql.Append("CFirst=@CFirst");
            strSql.Append(" where CNO=@CNO ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@CNO",    SqlDbType.VarChar, 50),
                new SqlParameter("@CName",  SqlDbType.VarChar, 50),
                new SqlParameter("@Credit", SqlDbType.Float,    8),
                new SqlParameter("@CFirst", SqlDbType.VarChar, 50)
            };
            parameters[0].Value = model.CNO;
            parameters[1].Value = model.CName;
            parameters[2].Value = model.Credit;
            parameters[3].Value = model.CFirst;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #2
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public StudentMS.Model.Course GetModel(string CNO)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 CNO,CName,Credit,CFirst from Course ");
            strSql.Append(" where CNO=@CNO ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@CNO", SqlDbType.VarChar, 50)
            };
            parameters[0].Value = CNO;

            StudentMS.Model.Course model = new StudentMS.Model.Course();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                model.CNO   = ds.Tables[0].Rows[0]["CNO"].ToString();
                model.CName = ds.Tables[0].Rows[0]["CName"].ToString();
                if (ds.Tables[0].Rows[0]["Credit"].ToString() != "")
                {
                    model.Credit = decimal.Parse(ds.Tables[0].Rows[0]["Credit"].ToString());
                }
                model.CFirst = ds.Tables[0].Rows[0]["CFirst"].ToString();
                return(model);
            }
            else
            {
                return(null);
            }
        }
コード例 #3
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(StudentMS.Model.Course model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into Course(");
            strSql.Append("CNO,CName,Credit,CFirst)");
            strSql.Append(" values (");
            strSql.Append("@CNO,@CName,@Credit,@CFirst)");
            SqlParameter[] parameters =
            {
                new SqlParameter("@CNO",    SqlDbType.VarChar, 50),
                new SqlParameter("@CName",  SqlDbType.VarChar, 50),
                new SqlParameter("@Credit", SqlDbType.Float,    8),
                new SqlParameter("@CFirst", SqlDbType.VarChar, 50)
            };
            parameters[0].Value = model.CNO;
            parameters[1].Value = model.CName;
            parameters[2].Value = model.Credit;
            parameters[3].Value = model.CFirst;

            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }