예제 #1
0
        public bool delete(userform_gettersetters gs)
        {
            bool          isSuccess = false;
            SqlConnection conn      = new SqlConnection(connstring);

            try
            {
                string     sql = "DELETE FROM users_table WHERE id=@id";
                SqlCommand cmd = new SqlCommand(sql, conn);

                //cmd.Parameters.AddWithValue("@id", gs.id);

                conn.Open();

                int rows = cmd.ExecuteNonQuery();

                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                conn.Close();
            }
            return(isSuccess);
        }
예제 #2
0
        public bool update(userform_gettersetters gs)
        {
            bool          isSuccess = false;
            SqlConnection conn      = new SqlConnection(connstring);

            try
            {
                string     sql = "UPDATE users_table SET first_name=@first_name, last_name=@last_name, username=@username, password=@password, contact=@contact, email=@email, gender=@gender, user_type=@user_type, added_date=@added_date WHERE id=@id";
                SqlCommand cmd = new SqlCommand(sql, conn);

                /*cmd.Parameters.AddWithValue("@first_name", gs.first_name);
                 * cmd.Parameters.AddWithValue("@last_name", gs.last_name);
                 * cmd.Parameters.AddWithValue("@username", gs.username);
                 * cmd.Parameters.AddWithValue("@password", gs.password);
                 * cmd.Parameters.AddWithValue("@contact", gs.contact);
                 * cmd.Parameters.AddWithValue("@email", gs.email);
                 * cmd.Parameters.AddWithValue("@gender", gs.gender);
                 * cmd.Parameters.AddWithValue("@user_type", gs.user_type);
                 * cmd.Parameters.AddWithValue("@added_date", gs.added_date);
                 * cmd.Parameters.AddWithValue("@id", gs.id);*/

                conn.Open();

                int rows = cmd.ExecuteNonQuery();

                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                conn.Close();
            }
            return(isSuccess);
        }
예제 #3
0
        public bool insert(userform_gettersetters gs)
        {
            bool          isSuccess = false;
            SqlConnection conn      = new SqlConnection(connstring);

            try
            {
                string     sql = "INSERT INTO users_table (first_name, last_name, username, password, contact, email, gender, user_type, added_date) VALUES(@first_name, @last_name, @username, @password, @contact, @email, @gender, @user_type, @added_date)";
                SqlCommand cmd = new SqlCommand(sql, conn);

                /*cmd.Parameters.AddWithValue("@first_name", gs.first_name);
                *  cmd.Parameters.AddWithValue("@last_name", gs.last_name);
                *  cmd.Parameters.AddWithValue("@username", gs.username);
                *  cmd.Parameters.AddWithValue("@password", gs.password);
                *  cmd.Parameters.AddWithValue("@contact", gs.contact);
                *  cmd.Parameters.AddWithValue("@email", gs.email);
                *  cmd.Parameters.AddWithValue("@gender", gs.gender);
                *  cmd.Parameters.AddWithValue("@user_type", gs.user_type);
                *  cmd.Parameters.AddWithValue("@added_date", gs.added_date);*/

                conn.Open();

                int rows = cmd.ExecuteNonQuery();

                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                conn.Close();
            }
            return(isSuccess);
        }