示例#1
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(ScoreManage.Model.StudInfo model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update StudInfo set ");
            strSql.Append("studName=SQL2012studName,");
            strSql.Append("studSex=SQL2012studSex,");
            strSql.Append("studBirthDay=SQL2012studBirthDay,");
            strSql.Append("classID=SQL2012classID");
            strSql.Append(" where studNo=SQL2012studNo ");
            SqlParameter[] parameters =
            {
                new SqlParameter("SQL2012studName",     SqlDbType.NVarChar,  255),
                new SqlParameter("SQL2012studSex",      SqlDbType.NVarChar,  255),
                new SqlParameter("SQL2012studBirthDay", SqlDbType.DateTime),
                new SqlParameter("SQL2012classID",      SqlDbType.NVarChar,  255),
                new SqlParameter("SQL2012studNo",       SqlDbType.NVarChar, 255)
            };
            parameters[0].Value = model.studName;
            parameters[1].Value = model.studSex;
            parameters[2].Value = model.studBirthDay;
            parameters[3].Value = model.classID;
            parameters[4].Value = model.studNo;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#2
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public ScoreManage.Model.StudInfo DataRowToModel(DataRow row)
 {
     ScoreManage.Model.StudInfo model = new ScoreManage.Model.StudInfo();
     if (row != null)
     {
         if (row["studNo"] != null)
         {
             model.studNo = row["studNo"].ToString();
         }
         if (row["studName"] != null)
         {
             model.studName = row["studName"].ToString();
         }
         if (row["studSex"] != null)
         {
             model.studSex = row["studSex"].ToString();
         }
         if (row["studBirthDay"] != null && row["studBirthDay"].ToString() != "")
         {
             model.studBirthDay = DateTime.Parse(row["studBirthDay"].ToString());
         }
         if (row["classID"] != null)
         {
             model.classID = row["classID"].ToString();
         }
     }
     return(model);
 }
示例#3
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(ScoreManage.Model.StudInfo model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into StudInfo(");
            strSql.Append("studNo,studName,studSex,studBirthDay,classID)");
            strSql.Append(" values (");
            strSql.Append("SQL2012studNo,SQL2012studName,SQL2012studSex,SQL2012studBirthDay,SQL2012classID)");
            SqlParameter[] parameters =
            {
                new SqlParameter("SQL2012studNo",       SqlDbType.NVarChar,  255),
                new SqlParameter("SQL2012studName",     SqlDbType.NVarChar,  255),
                new SqlParameter("SQL2012studSex",      SqlDbType.NVarChar,  255),
                new SqlParameter("SQL2012studBirthDay", SqlDbType.DateTime),
                new SqlParameter("SQL2012classID",      SqlDbType.NVarChar, 255)
            };
            parameters[0].Value = model.studNo;
            parameters[1].Value = model.studName;
            parameters[2].Value = model.studSex;
            parameters[3].Value = model.studBirthDay;
            parameters[4].Value = model.classID;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#4
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ScoreManage.Model.StudInfo GetModel(string studNo)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 studNo,studName,studSex,studBirthDay,classID from StudInfo ");
            strSql.Append(" where studNo=SQL2012studNo ");
            SqlParameter[] parameters =
            {
                new SqlParameter("SQL2012studNo", SqlDbType.NVarChar, 255)
            };
            parameters[0].Value = studNo;

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

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }