S
s.bussing
Hi all, I got this problem. I've got three table User, Group and
User_Group. These tables I have put into a typed dataset and added
relations to them. I also have a form in which it is possible to
insert, update or delete a user, including the related records in the
table User_Group. This works fine if I insert or update a user. But
when I try to delete the user, I got this error message "Concurrency
Voilation: DeleteCommand affected 0 rows". If however I switch the the
order in which the DataAdapter.update methods are called, the delete
actions throws no error, but then it is not possible to insert or
update the user table.
It seems dat if I delete the user first, in de dataset the relation
between User_Group and User tables is not there anymore, so the
adapterupdate fails.
Anyone have a solution for this?
See the code I use:
public void UpdateBEUser(BEUser BeUser)
{
OpenConnection(sqlConn);
SqlTransaction sqlTransAction = sqlConn.BeginTransaction();
try
{
SetTransaction(sqlTransAction,sqlConn,sqlDAUserBEUser,sqlDAUserGroupBEUser);
if (BeUser.HasChanges())
{
DataTable dtUserGroup = BeUser.User_Group.GetChanges();
if (!BeUser.User.GetChanges().Rows.Count.Equals(0))
sqlDAUserBEUser.Update(BeUser,"User");
else _UserId = (int)BeUser.User.Rows[0]["UserId"];
if (dtUserGroup != null)
if (!dtUserGroup.Rows.Count.Equals(0))
{
foreach (DataRow _UserGroupRow in dtUserGroup.Rows)
{
if (_UserGroupRow.RowState.Equals(DataRowState.Added))
_UserGroupRow["User_id"] = _UserId;
}
sqlDAUserGroupBEUser.Update(BeUser,"User_Group");
}
}
BeUser.AcceptChanges();
sqlTransAction.Commit();
}
catch (Exception Ex)
{
string ErrorMessage = Ex.Message;
sqlTransAction.Rollback();
}
finally
{
CloseConnection(sqlConn);
}
}
User_Group. These tables I have put into a typed dataset and added
relations to them. I also have a form in which it is possible to
insert, update or delete a user, including the related records in the
table User_Group. This works fine if I insert or update a user. But
when I try to delete the user, I got this error message "Concurrency
Voilation: DeleteCommand affected 0 rows". If however I switch the the
order in which the DataAdapter.update methods are called, the delete
actions throws no error, but then it is not possible to insert or
update the user table.
It seems dat if I delete the user first, in de dataset the relation
between User_Group and User tables is not there anymore, so the
adapterupdate fails.
Anyone have a solution for this?
See the code I use:
public void UpdateBEUser(BEUser BeUser)
{
OpenConnection(sqlConn);
SqlTransaction sqlTransAction = sqlConn.BeginTransaction();
try
{
SetTransaction(sqlTransAction,sqlConn,sqlDAUserBEUser,sqlDAUserGroupBEUser);
if (BeUser.HasChanges())
{
DataTable dtUserGroup = BeUser.User_Group.GetChanges();
if (!BeUser.User.GetChanges().Rows.Count.Equals(0))
sqlDAUserBEUser.Update(BeUser,"User");
else _UserId = (int)BeUser.User.Rows[0]["UserId"];
if (dtUserGroup != null)
if (!dtUserGroup.Rows.Count.Equals(0))
{
foreach (DataRow _UserGroupRow in dtUserGroup.Rows)
{
if (_UserGroupRow.RowState.Equals(DataRowState.Added))
_UserGroupRow["User_id"] = _UserId;
}
sqlDAUserGroupBEUser.Update(BeUser,"User_Group");
}
}
BeUser.AcceptChanges();
sqlTransAction.Commit();
}
catch (Exception Ex)
{
string ErrorMessage = Ex.Message;
sqlTransAction.Rollback();
}
finally
{
CloseConnection(sqlConn);
}
}