Beispiel #1
0
        public static bool deletePost(int postID)
        {
            bool success = false;

            DataAccessLayer DAL = new DataAccessLayer();
            try
            {
                DAL.delete(String.Format("postID = '{0}'", postID), "Posts");
            }
            catch (Exception ex)
            {
                Console.Write("ERROR: could not delete post ---- " + ex.Message);
            }
            return success;
        }
Beispiel #2
0
        public bool InsertStatus(DemoModel Status)
        {
            DataAccessLayer dal = new DataAccessLayer();
            bool Success = true;
            try
            {
                /* Testing Insert */
                Dictionary<string, string> dict = new Dictionary<string,string>();
                dict.Add("StatusName", Status.StatusName);
                // no need to add statusID, as that column is an identity column
                dal.insert(dict, "TransactionStatus");

                /* Testing Select */
                DataTable dt = new DataTable();
                dt = dal.select("StatusName = 'a'", "TransactionStatus");
                foreach (DataRow row in dt.Rows) // Loop over the rows.
                {
                    foreach (var col in row.ItemArray)
                    {
                        Debug.Write(col);
                    }
                    Debug.Write('\n');
                }

                /* Testing Update */
                Dictionary<string, string> d = new Dictionary<string, string>();
                d.Add("StatusName", "'asma_rox'");
                dal.update("TransactionStatus", "StatusName = 'asma_sux'", d);
                /* Manually go into SQL Server to see if the row is correctly updated */

                /* Testing Delete */
                dal.delete("StatusName = 'johnny'", "TransactionStatus");
                /* now the db should not contain an entry with StatusName = 'johnny' */

            }
            catch (Exception)
            {
                Success = false;
            }
            return Success;
        }