private void button1_Click(object sender, EventArgs e)
{
try
{
con.Open();
da = new OracleDataAdapter("select userid, firstname, lastname, salary, location from test_dummy", con);
ds = new DataSet();
cmdbld = new OracleCommandBuilder(da);
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
dataGridView1.Columns["userid"].ReadOnly = true;
dataGridView1.Columns["userid"].DefaultCellStyle.BackColor = Color.Red;
dataGridView1.Columns["userid"].DefaultCellStyle.ForeColor = Color.White;
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
con.Close();
}
}
private void button7_Click(object sender, EventArgs e)
{
DialogResult dialog = MessageBox.Show("Update?",
"", MessageBoxButtons.YesNo);
if (dialog == DialogResult.Yes)
{
if (dataGridView1.Columns["location"] == null)
try
{
da.Update(ds.Tables[0]);
MessageBox.Show("Data updated");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
con.Close();
button1_Click(sender, e);
}
if (dataGridView1.Columns["location"] != null)
{
MessageBox.Show("You can not update this line due to location filled");
button1_Click(sender, e);
}
}
if (dialog == DialogResult.No)
{
MessageBox.Show("No change has been made.");
button1_Click(sender, e);
}
}
这是代码。如何对行设置限制,以使具有位置的行不能被删除但可以更新?我将其设置为只读,因此无法更新位置,但不会阻止其被删除。是的,我知道我可以决定不使用Commander Builder来使事情变得更灵活,但是如果这样做,我将失去一次编辑多个行的自由。请帮助。