Ejemplo n.º 1
0
        //Insering data to the database
        public bool Insert(TagsClass c)
        {
            //creating default retun type and setting its value to false
            bool isSuccess = false;

            //step 1 : connect database
            SQLiteConnection conn = new Classes.SqliteHelper().GetSQLiteConnection();

            try
            {
                //sql query to insert data
                string sql = "Insert into ManageTag (SubjectName , SubjectCode , RelatedTag) values ( @SubjectName , @SubjectCode , @RelatedTag)";
                //creating cmd usin sql and conn
                SQLiteCommand cmd = new SQLiteCommand(sql, conn);

                //create parameters to add data
                cmd.Parameters.AddWithValue("@SubjectName", c.TagName);
                cmd.Parameters.AddWithValue("@SubjectCode", c.TagCode);
                cmd.Parameters.AddWithValue("@RelatedTag", c.RelatedTag);

                //connection open
                conn.Open();

                int rows = cmd.ExecuteNonQuery();

                //if the query runs successfully then the value of rows will be greater than zero else its value will be zero
                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                conn.Close();
            }
            return(isSuccess);
        }
Ejemplo n.º 2
0
        //Method to update data in database
        public bool Update(TagsClass c)
        {
            //create a default return type and set its value to false
            bool isSuccess = false;

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

            try
            {
                //sql to update data in database
                string sql = "Update ManageTag set SubjectName =@SubjectName , SubjectCode =@SubjectCode , RelatedTag=@RelatedTag where TagID =@TagID";

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

                //create parameters to add values
                cmd.Parameters.AddWithValue("@SubjectName", c.TagName);
                cmd.Parameters.AddWithValue("@SubjectCode", c.TagCode);
                cmd.Parameters.AddWithValue("@RelatedTag", c.RelatedTag);
                cmd.Parameters.AddWithValue("TagID", c.TagID);

                //open DB connection
                conn.Open();

                int rows = cmd.ExecuteNonQuery();
                //if the query runs successfully then the value of rows will be greater than zero else its value will be zero
                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                conn.Close();
            }
            return(isSuccess);
        }
Ejemplo n.º 3
0
        //Method to delete data in database
        public bool Delete(TagsClass c)
        {
            //default return value and set if false
            bool isSuccess = false;
            //create sql connection
            SQLiteConnection conn = new Classes.SqliteHelper().GetSQLiteConnection();

            try
            {
                //sql to delete data
                string sql = "Delete from ManageTag where TagID = @TagID";

                //creating sql command
                SQLiteCommand cmd = new SQLiteCommand(sql, conn);
                cmd.Parameters.AddWithValue("@TagID", c.TagID);

                //open connection
                conn.Open();

                int rows = cmd.ExecuteNonQuery();
                //if run success value will be greater than ero othrwise it will be zero
                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                //close connection
                conn.Close();
            }

            return(isSuccess);
        }