示例#1
0
        public int Update(StudentDto student)
        {
            ConnectionControl();
            SqlCommand sqlCommand = new SqlCommand(
                "update Students set Tc = @tc, Name = @name, Surname = @surname, Department = @department, City = @city where Id = @id", _sqlConnection);

            sqlCommand.Parameters.AddWithValue("@tc", student.Tc);
            sqlCommand.Parameters.AddWithValue("@name", student.Name);
            sqlCommand.Parameters.AddWithValue("@surname", student.Surname);
            sqlCommand.Parameters.AddWithValue("@department", student.Bolum);
            sqlCommand.Parameters.AddWithValue("@city", student.City);
            sqlCommand.Parameters.AddWithValue("@id", student.Id);

            int i = sqlCommand.ExecuteNonQuery();

            _sqlConnection.Close();
            return(i);
        }
示例#2
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            ////zorunlu alanlar ve dogru bir tc girilmişmi kontrolü
            if (AnyMissingEntries().Count > 0)
            {
                string message = String.Join(",", AnyMissingEntries());
                MessageBox.Show(message, "UYARI", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            StudentDto  student     = new StudentDto();
            StudentAdap studentAdap = new StudentAdap();

            //eğer DataGridView 'den herhangi bir kayıt seçilmeden Update butonuna basıldığında
            //programın kırılmasını engelleyip, kullanıcıyı uyarmak için try - catch kullandık.
            try
            {
                student.Id = Convert.ToInt32(dgStudents.CurrentRow.Cells[0].Value);
            }
            catch (NullReferenceException)
            {
                MessageBox.Show("Lütfen güncellemek istediğiniz kaydı seçiniz!!", "Uyarı", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            student.Id      = Convert.ToInt32(dgStudents.CurrentRow.Cells[0].Value);
            student.Tc      = txtTc.Text;
            student.Name    = txtName.Text;
            student.Surname = txtSurname.Text;
            student.Bolum   = cbDepartment.Text;
            student.City    = cbCity.Text;

            int i = studentAdap.Update(student);

            if (i > 0)
            {
                MessageBox.Show("Kayıt başarıyle güncellendi.", "Bilgilendirme", MessageBoxButtons.OK, MessageBoxIcon.Information);
                LoadStudent();
            }
            else
            {
                MessageBox.Show("İşlem başarısız olmuştur!", "Uyarı", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }