I have a DataGridView that has CheckBox Field. I am trying to update Checkbox values in database. But it's giving me this Error. I already implement method ufGview_DataError
with value e.Cancel = true
. I am interested to store 0 when it will be Checked and 1 when it will be Unchecked. Sometimes it is updating values but most of the time not doing anything. I am using C# with Sql Server 2008 R2 Express Edition
Here is method that i am using to update database values
if (e.ColumnIndex == 3)
{
if (ufGview.Rows[e.RowIndex].Cells["Column2"].Value != null)
{
bool a = Convert.ToBoolean(ufGview.Rows[e.RowIndex].Cells["Column2"].Value);
int i;
if (a == true)
{
i = 0;
}
else
{
i = 1;
}
UpdatePermissions(ufGview.Rows[e.RowIndex].Cells["Column1"].Value.ToString(), i);
}
}
Here is Method of UpdatePermissions
private void UpdatePermissions(string p, int a)
{
CheckConnectionStatus();
try
{
sqlConnection.Open();
sqlCommand = new SqlCommand("Update FamilyMembers Set status=@status where Id=@Id", sqlConnection);
sqlCommand.Parameters.AddWithValue("@status", a);
sqlCommand.Parameters.AddWithValue("@Id", p);
sqlDataReader = sqlCommand.ExecuteReader();
sqlConnection.Close();
}
catch (Exception exp)
{
MessageBox.Show(exp.Message.ToString(), "Exception in UpdatePermissions");
}
finally
{
CheckConnectionStatus();
}
}
Please help me to fix this issue shown in Snapshot as well.