コード例 #1
0
        // 刪除我的最愛
        public string delMyFavorite(string user_ID, int job_ID)
        {
            #region [做DB連線 以及 執行DB處理]

            // 建立DB連線
            Tools.DBConnection bsc = new Tools.DBConnection();

            // 刪除 commentID的資料
            String doDB = bsc.ActionDB(
                string.Format(
                    @"DELETE FROM [MyFavorite]
                              WHERE 1=1
                              AND USER_ID = '{0}'
                              AND JOB_ID = {1}"
                    , user_ID, job_ID)
                );

            // 如果 doDB為"success" ,代表DB連線成功 ,反之失敗
            if (doDB != "success")
            {
                return("DB處理錯誤");
            }

            #endregion

            #region [檢查DB內容]

            // 查看是否刪除成功
            DataTable dt = bsc.ReadDB(
                string.Format(
                    @"SELECT JOB_ID
                                  FROM [MyFavorite] 
                                  WHERE 1=1
                                  AND USER_ID = '{0}'
                                  AND JOB_ID = {1}"
                    , user_ID, job_ID)
                );

            // 判斷 DB 是否還有一模一樣的資料筆
            if (dt.Rows.Count == 0)
            {
                return("delete error!");
            }
            else
            {
                return("delete success!");
            }

            #endregion
        }
コード例 #2
0
        // 新增我的最愛
        public string insertMyFavorite(string user_ID, int job_ID)
        {
            #region [做DB連線 以及 執行DB處理]

            // 建立DB連線
            Tools.DBConnection bsc = new Tools.DBConnection();

            // 放入 我的最愛的資料
            string doDB = bsc.ActionDB(
                string.Format(
                    @"INSERT INTO [MyFavorite] (USER_ID,JOB_ID)
                              VALUES('{0}',{1});"
                    , user_ID, job_ID)
                );

            // 如果 doDB為"success" ,代表DB連線成功 ,反之失敗
            if (doDB != "success")
            {
                return("DB處理錯誤");
            }

            #endregion

            #region [檢查DB內容]

            // 查看是否新增成功
            DataTable dt = bsc.ReadDB(
                string.Format(
                    @"SELECT JOB_ID
                                  FROM [MyFavorite] 
                                  WHERE 1=1
                                  AND USER_ID = '{0}'
                                  AND JOB_ID = {1}"
                    , user_ID, job_ID)
                );

            // 判斷 DB 是否有插入一模一樣的資料筆
            if (dt.Rows.Count == 0)
            {
                return("insert success!");
            }
            else
            {
                return("insert error!");
            }

            #endregion
        }