示例#1
0
        //update data in database
        public bool Update(ManageStudentClass m)
        {
            //default return type and set its value to false
            bool isSuccess = false;

            SQLiteConnection conn = new Classes.SqliteHelper().GetSQLiteConnection();

            try
            {
                //sql to update data
                string sql = "Update StudentManage set AcademicYearSemester = @AcademicYearSemester, Programme = @Programme ,GroupNo = @GroupNo,SubGroupNo = @SubGroupNo ,GroupID = @GroupID , SubGroupID = @SubGroupID where ID = @ID ";

                //sql
                SQLiteCommand cmd = new SQLiteCommand(sql, conn);

                //create parameters to add value
                cmd.Parameters.AddWithValue("@AcademicYearSemester", m.AcademicYearSemester);
                cmd.Parameters.AddWithValue("@Programme", m.Program);
                cmd.Parameters.AddWithValue("@GroupNo", m.GroupNo);
                cmd.Parameters.AddWithValue("@SubGroupNo", m.SubGroupNo);
                cmd.Parameters.AddWithValue("@GroupID", m.GroupID);
                cmd.Parameters.AddWithValue("@SubGroupID", m.SubGroupID);
                cmd.Parameters.AddWithValue("ID", m.ID);

                //open database connection
                conn.Open();

                int rows = cmd.ExecuteNonQuery();
                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                conn.Close();
            }

            return(isSuccess);
        }
示例#2
0
        //Insering data into the database
        public bool Insert(ManageStudentClass m)
        {
            //creating a default return type
            bool isSuccess = false;

            //connect db
            SQLiteConnection conn = new Classes.SqliteHelper().GetSQLiteConnection();

            try
            {
                //sql to insert data
                string sql = "Insert into StudentManage (AcademicYearSemester, Programme ,GroupNo,SubGroupNo ,GroupID , SubGroupID) values (@AcademicYearSemester, @Programme ,@GroupNo,@SubGroupNo ,@GroupID , @SubGroupID)";
                //creating sql using sql and conn
                SQLiteCommand cmd = new SQLiteCommand(sql, conn);
                //create parameters to add data
                cmd.Parameters.AddWithValue("@AcademicYearSemester", m.AcademicYearSemester);
                cmd.Parameters.AddWithValue("@Programme", m.Program);
                cmd.Parameters.AddWithValue("@GroupNo", m.GroupNo);
                cmd.Parameters.AddWithValue("@SubGroupNo", m.SubGroupNo);
                cmd.Parameters.AddWithValue("@GroupID", m.GroupID);
                cmd.Parameters.AddWithValue("@SubGroupID", m.SubGroupID);

                //open connection
                conn.Open();

                int rows = cmd.ExecuteNonQuery();
                //if code success value of rows will greater than zero else its zero
                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                conn.Close();
            }

            return(isSuccess);
        }
示例#3
0
        //method to delete data in DB
        public bool Delete(ManageStudentClass m)
        {
            //create a default retun value and set it value to false
            bool isSuccess = false;
            //create sql connection
            SQLiteConnection conn = new Classes.SqliteHelper().GetSQLiteConnection();

            try
            {
                //sql to delete data
                string sql = "Delete from StudentManage where ID = @ID";

                //creating sql command
                SQLiteCommand cmd = new SQLiteCommand(sql, conn);
                cmd.Parameters.AddWithValue("@ID", m.ID);
                //open connection
                conn.Open();

                int rows = cmd.ExecuteNonQuery();
                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                conn.Close();
            }
            return(isSuccess);
        }