private void tsbtnNew_Click(object sender, EventArgs e) { var newuser = new NewTableGroup(0); var result = newuser.ShowDialog(); if (result == DialogResult.OK) { try { conn = new SqlConnection(connStr); conn.Open(); cmd = new SqlCommand(); cmd = conn.CreateCommand(); cmd.CommandText = "Insert Into TableGroup (Name,Status) Values (@Name,@Status)"; cmd.Parameters.AddRange(new SqlParameter[] { new SqlParameter("Name", newuser.name), new SqlParameter("Status", newuser.status) }); value = (int)cmd.ExecuteNonQuery(); if (value > 0) { Msg msg = new Msg("Məlumat uğurla daxil olundu", 221); msg.ShowDialog(); cmd.Dispose(); ShowTable(); } else { Msg msg = new Msg("Xəta baş verdi, məlumat daxil edilmədi", 237); msg.ShowDialog(); } conn.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); throw; } finally { } } }
private void tsbtnEdit_Click(object sender, EventArgs e) { var newuser = new NewTableGroup(id); var result = newuser.ShowDialog(); if (result == DialogResult.OK) { try { conn = new SqlConnection(connStr); conn.Open(); cmd = new SqlCommand(); cmd = conn.CreateCommand(); cmd.CommandText = "Update TableGroup Set Name=@Name Where Id=@Id"; cmd.Parameters.AddRange(new SqlParameter[] { new SqlParameter("@Id", id), new SqlParameter("@Name", newuser.name), }); value = (int)cmd.ExecuteNonQuery(); if (value == 1) { Msg msg = new Msg("Məlumat uğurla dəyişdirildi", 221); msg.ShowDialog(); cmd.Dispose(); ShowTable(); } else { Msg msg = new Msg("Xəta baş verdi, dəyişdirilmədi", 237); msg.ShowDialog(); } conn.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); throw; } finally { } } }