我正在尝试将gridview复选框值更新到数据库中,这是我的代码,但它没有更新
问题描述:
public void fnsave()
{
int i = 0;
foreach (DataGridViewRow row in dataGridView1.SelectedRows)
{
bool status = false;
if (Convert.ToBoolean(String.IsNullOrEmpty(row.Cells["AllowAction"].Value.ToString().Trim()) ? "False" : row.Cells["AllowAction"].Value.ToString()))
{
string modulename = row.Cells["ModuleName"].Value.ToString();
status = true;
i = user.SavePermission(Convert.ToInt32(cmbPermissions.SelectedValue), modulename, Convert.ToBoolean(row.Cells["AllowAction"].Value.ToString()));
}
if (i > 0)
{
MessageBox.Show("Permission Details Added Successfully");
}
else
{
status = false;
}
}
}
private void btnUpdate_Click(object sender, EventArgs e)
{
fnsave();
}
答
try
{
oledbCmdBuilder = new OleDbCommandBuilder(oledbAdapter);
changes = ds.GetChanges();
if (changes != null)
{
oledbAdapter.Update(ds.Tables[0]);
}
ds.AcceptChanges();
MessageBox.Show("Save Changes", "Saved?", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Close();
Frm_Reports obj = new Frm_Reports();
obj.Show();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
尝试此代码工作正常。
try this code is working fine.