Ejemplo n.º 1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (formState == "Add")
            {
                SqlCommand command = new SqlCommand($"insert into Employees values('{txtName.Text}')", DB_Common.connection);

                DB_Common.OpenConnection();
                command.ExecuteNonQuery();
                DB_Common.CloseConnection();

                RefreshDataGridView();
            }
            else if (formState == "Update")
            {
                SqlCommand command = new SqlCommand($"update Employees Set EmployeeName = '{txtName.Text}' where EmployeeId = {txtEmployeeId.Text}", DB_Common.connection);

                DB_Common.OpenConnection();
                command.ExecuteNonQuery();
                DB_Common.CloseConnection();

                RefreshDataGridView();

                formState          = "Add";
                txtName.Text       = "";
                txtEmployeeId.Text = "";
                txtName.Focus();
            }
        }
Ejemplo n.º 2
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            SqlCommand command = new SqlCommand($"Delete from Employees where EmployeeId = {txtEmployeeId.Text}", DB_Common.connection);

            DB_Common.OpenConnection();
            command.ExecuteNonQuery();
            DB_Common.CloseConnection();

            RefreshDataGridView();

            formState          = "Add";
            txtName.Text       = "";
            txtEmployeeId.Text = "";
            txtName.Focus();
        }