Beispiel #1
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public MvcApplication1.Model.Student DataRowToModel(DataRow row)
 {
     MvcApplication1.Model.Student model = new MvcApplication1.Model.Student();
     if (row != null)
     {
         if (row["StudentID"] != null && row["StudentID"].ToString() != "")
         {
             model.StudentID = int.Parse(row["StudentID"].ToString());
         }
         if (row["LastName"] != null)
         {
             model.LastName = row["LastName"].ToString();
         }
         if (row["FirstMidName"] != null)
         {
             model.FirstMidName = row["FirstMidName"].ToString();
         }
         if (row["EnrollmentDate"] != null && row["EnrollmentDate"].ToString() != "")
         {
             model.EnrollmentDate = DateTime.Parse(row["EnrollmentDate"].ToString());
         }
         if (row["age"] != null && row["age"].ToString() != "")
         {
             model.age = int.Parse(row["age"].ToString());
         }
     }
     return model;
 }
Beispiel #2
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public MvcApplication1.Model.Student GetModel(int StudentID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 StudentID,LastName,FirstMidName,EnrollmentDate,age from Student ");
            strSql.Append(" where StudentID=@StudentID");
            SqlParameter[] parameters = {
                    new SqlParameter("@StudentID", SqlDbType.Int,4)
            };
            parameters[0].Value = StudentID;

            MvcApplication1.Model.Student model = new MvcApplication1.Model.Student();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }