예제 #1
0
        public static List <Dictionary <string, object> > getMarksByStudentId(Marks param)
        {
            Marks obj = new Marks();

            obj.studentId = param.studentId;
            DataSet   ds = new DataSet();
            DataTable dt = new DataTable();
            List <Dictionary <string, object> > rows = new List <Dictionary <string, object> >();
            Dictionary <string, object>         row;
            SqlConnection conn = new SqlConnection();

            conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);

            string         query = "select * from mst_marks where student_id='" + obj.studentId + "'";
            SqlDataAdapter adp   = new SqlDataAdapter(query, conn);

            adp.Fill(ds);
            dt = ds.Tables[0];

            if (dt.Rows.Count <= 0)
            {
                row = new Dictionary <string, object>();
                row.Add("Message", "Student Not Found");
                rows.Add(row);
            }
            else
            {
                foreach (DataRow dr in dt.Rows)
                {
                    row = new Dictionary <string, object>();
                    foreach (DataColumn col in dt.Columns)
                    {
                        row.Add(col.ColumnName, dr[col]);
                    }
                    rows.Add(row);
                }
            }

            return(rows);
        }
예제 #2
0
        public static List <Dictionary <string, object> > postMarks(Marks param)
        {
            Marks obj = new Marks();
            List <Dictionary <string, object> > rows;

            obj.id        = param.id;
            obj.studentId = param.studentId;
            obj.marks     = param.marks;
            bool flag = studentExist(obj.studentId);

            if (flag)
            {
                rows = new List <Dictionary <string, object> >();
                Dictionary <string, object> row;
                row = new Dictionary <string, object>();
                row.Add("Message", "Student Not Found");
                rows.Add(row);
            }
            else
            {
                SqlConnection conn = new SqlConnection();
                conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);

                if (conn.State == ConnectionState.Closed)
                {
                    conn.Open();
                }

                string     query = "insert into mst_marks values('" + obj.studentId + "','" + obj.marks + "')";
                SqlCommand com   = new SqlCommand(query, conn);
                com.ExecuteNonQuery();
                conn.Close();
                rows = getMarks();
            }


            return(rows);
        }
예제 #3
0
        public static List <Dictionary <string, object> > deleteMarks(Marks param)
        {
            Marks obj = new Marks();
            List <Dictionary <string, object> > rows;


            obj.id = param.id;
            bool flag = MarksExist(obj.id);

            if (flag)
            {
                rows = new List <Dictionary <string, object> >();
                Dictionary <string, object> row;
                row = new Dictionary <string, object>();
                row.Add("Message", "Marks Not Found");
                rows.Add(row);
            }
            else
            {
                SqlConnection conn = new SqlConnection();
                conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);

                if (conn.State == ConnectionState.Closed)
                {
                    conn.Open();
                }

                string     query = "delete mst_marks where id = '" + obj.id + "'";
                SqlCommand com   = new SqlCommand(query, conn);
                com.ExecuteNonQuery();
                conn.Close();

                rows = getMarks();
            }

            return(rows);
        }