Beispiel #1
0
        private void deleteUser()
        {
            string        errInsert = string.Empty;
            cKoneksi      koneksi   = new cKoneksi();
            SqlConnection conn      = new SqlConnection(koneksi.konekMsSql('1'));//koneksi ke 64 db parkir

            cQuery     qr  = new cQuery();
            SqlCommand cmd = null;

            try
            {
                conn.Open();

                cmd = new SqlCommand(qr.qDeleteUserWhereUsernameAndPass(), conn);
                cmd.Parameters.AddWithValue("@username", txt_username.Text);
                cmd.Parameters.AddWithValue("@password", txt_password.Text);

                cmd.ExecuteNonQuery();//insert ke sql
            }
            catch (Exception ex)
            {
                errInsert = ex.Message;
                MessageBox.Show(errInsert, "BSI UMY", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                conn.Close();
                conn.Dispose();
            }

            if (errInsert == string.Empty)
            {
                label_message.Text = "User Berahasil dihapus";
            }

            //string err = string.Empty;
            //cQuery qr = new cQuery();
            //cKoneksi koneksi = new cKoneksi();
            //using (var conn = new SQLiteConnection(koneksi.LokasiSqlite()))//koneksi ke sqlite
            //{
            //    try
            //    {
            //        conn.Open();//buka koneksi
            //        using (var cmd = new SQLiteCommand(conn))
            //        {
            //            using (var transaction = conn.BeginTransaction())
            //            {
            //                cmd.CommandText = qr.qDeleteUserWhereUsernameAndPass();//" Delete from user where username = @username and password = @password ";
            //                cmd.Parameters.Clear();
            //                cmd.Prepare();
            //                cmd.Parameters.AddWithValue("@username", txt_username.Text);
            //                cmd.Parameters.AddWithValue("@password", txt_password.Text);
            //                cmd.ExecuteNonQuery();

            //                transaction.Commit();
            //            }
            //        }
            //    }
            //    catch(Exception ex)
            //    {
            //        MessageBox.Show(ex.Message);
            //    }
            //    finally
            //    {
            //        conn.Close(); //tutup koneksi
            //        conn.Dispose();
            //    }
            //}
            //if (err == string.Empty)
            //{
            //    MessageBox.Show("Username berhasil dihapus");
            //}
        }