private void btnAddMem_Click(object sender, EventArgs e) { MemberForm dlg = new MemberForm(); if (dlg.ShowDialog() == DialogResult.OK) { string qry = string.Format("INSERT INTO tblMember (Name,Grade,Byear,Tel," + "Addr,Money) VALUES ('{0}',{1},{2},'{3}','{4}',{5})", dlg.Name1, dlg.Grade, dlg.BYear, dlg.Tel, dlg.Addr, dlg.Money); SqlCommand Com = new SqlCommand(qry, Con); Com.ExecuteNonQuery(); RefreshMember(); } }
private void btnEditMem_Click(object sender, EventArgs e) { int Pk; if (lvMember.SelectedItems.Count == 0) { MessageBox.Show("수정할 회원을 먼저 선택하십시오."); return; } Pk = Convert.ToInt32(lvMember.SelectedItems[0].SubItems[0].Text); MemberForm dlg = new MemberForm(); dlg.radioButton1.Enabled = false; dlg.radioButton2.Enabled = false; dlg.radioButton3.Enabled = false; SqlCommand Com = new SqlCommand("SELECT Name, Byear, Money, Tel, Addr, Grade FROM " + "tblMember WHERE Pk = " + Pk.ToString(), Con); SqlDataReader R = Com.ExecuteReader(); R.Read(); dlg.Name1 = R["Name"].ToString(); dlg.BYear = (int)R["BYear"]; dlg.Money = (int)R["Money"]; dlg.Tel = R["Tel"].ToString(); dlg.Addr = R["Addr"].ToString(); dlg.Grade = (int)R["Grade"]; R.Close(); if (dlg.ShowDialog() == DialogResult.OK) { string qry = string.Format("UPDATE tblMember Set Name = '{0}', Grade = {1}, "+ "Byear = {2}, Tel = '{3}', Addr = '{4}', Money = {5} WHERE Pk = {6}", dlg.Name1, dlg.Grade, dlg.BYear, dlg.Tel, dlg.Addr, dlg.Money, Pk); Com = new SqlCommand(qry, Con); Com.ExecuteNonQuery(); RefreshMember(); } }