In what order to call sever DataAdapters to update a typed dataset

  • Thread starter Thread starter s.bussing
  • Start date Start date
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);
}
}
 
You know the dependencies.

INSERT
User and Group - order really does not matter here
User_Group

UPDATE
Technically any order

DELETE
User_Group
User and Group

Fill
User and Group
User_Group

Attributes from the dependencies works well to automate this on your data
layer.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*************************************************
Think outside of the box!
*************************************************
 
Back
Top