Пример #1
0
        private void Delete_Click(object sender, EventArgs e)
        {
            String DeleteString = "";
            int    kq           = 0;

            try
            {
                DataGridViewSelectedRowCollection array = dgv.SelectedRows;

                if (MessageBox.Show("Delete " + array.Count.ToString() + " Data ?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                {
                    foreach (DataGridViewRow dr in array)
                    {
                        string keyvalue = DBase.StringReturn(dr.Cells[colKEYCOL].Value);
                        if (keyvalue != "")
                        {
                            int res = DHuy.DELETE(TableName, KEYCOL, keyvalue);
                            if (res > 0)
                            {
                                kq++;
                                DeleteString = DeleteString + ",'" + keyvalue + "'";
                            }
                        }
                    }
                }
            }
            catch (Exception ex) {}
            if (kq > 0)
            {
                DeleteString = DeleteString.Substring(1, DeleteString.Length - 1);
                var rows = dt.Select(KEYCOL + " IN (" + DeleteString + ")");
                foreach (var row in rows)
                {
                    row.Delete();
                }
            }
        }