Пример #1
0
        public ActionResult createOrEditpassedoutyear(int id = 0)
        {
            if (id == 0)
            {
                return(View(new Passedoutyear()));
            }

            else
            {
                using (SqlConnection sqlCon = new SqlConnection(constrs))
                {
                    List <Passedoutyear> depart = new List <Passedoutyear>();
                    string     query1           = "select * from  Passedoutyear where id=@id;";
                    SqlCommand cmd = new SqlCommand(query1, sqlCon);
                    sqlCon.Open();
                    cmd.Parameters.AddWithValue("@id", id);
                    SqlDataReader sdr = cmd.ExecuteReader();
                    while (sdr.Read())
                    {
                        Passedoutyear newstud = new Passedoutyear();
                        newstud.id               = Convert.ToInt32(sdr["id"]) == 0 ? 0 : Convert.ToInt32(sdr["id"]);
                        newstud.passedoutyear    = (sdr["passedoutyear"]) == DBNull.Value ? string.Empty : sdr["passedoutyear"].ToString();
                        newstud.CreatedBy        = (sdr["CreatedBy"]) == DBNull.Value ? string.Empty : sdr["CreatedBy"].ToString();
                        newstud.CreatedTimestamp = (sdr["CreatedTimestamp"]) == DBNull.Value ? DateTime.Now : (DateTime)sdr["CreatedTimestamp"];

                        depart.Add(newstud);
                        return(View(newstud));
                    }
                    sdr.Close();
                    return(View());
                }
            }
        }
Пример #2
0
        public ActionResult GetallPassedout()
        {
            List <Passedoutyear> depart = new List <Passedoutyear>();

            try
            {
                string        query      = "select * from  Passedoutyear;";
                SqlConnection connection = new SqlConnection(constrs);
                SqlCommand    cmd        = new SqlCommand(query, connection);
                connection.Open();
                SqlDataReader sdr = cmd.ExecuteReader();
                while (sdr.Read())
                {
                    Passedoutyear newstud = new Passedoutyear();
                    newstud.id               = Convert.ToInt32(sdr["id"]) == 0 ? 0 : Convert.ToInt32(sdr["id"]);
                    newstud.passedoutyear    = (sdr["passedoutyear"]) == DBNull.Value ? string.Empty : sdr["passedoutyear"].ToString();
                    newstud.CreatedBy        = (sdr["CreatedBy"]) == DBNull.Value ? string.Empty : sdr["CreatedBy"].ToString();
                    newstud.CreatedTimestamp = (sdr["CreatedTimestamp"]) == DBNull.Value ? DateTime.Now : Convert.ToDateTime(sdr["CreatedTimestamp"]);
                    newstud.RoleName         = Session["RoleName"].ToString();
                    depart.Add(newstud);
                }
                sdr.Close();
                connection.Close();
                return(Json(new { data = depart }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                return(Json(depart, JsonRequestBehavior.AllowGet));
            }
        }