S
Scott Baker
Sort of a newby question...
I have a read only list view that is populated with information from a
dataset. If the user selects a listview item and presses the delete button,
then the item is removed fromt he list, and the underlying dataset is marked
as delete (all conditional and error checking has been removed for this
post):
expr = "RelationshipName ='" + relationshipName + "' AND LinkFromID = '" +
linkFromID + "' AND LinkToID = '" + linkToID + "'";
DataRow[] rows = this.objectObjectsTable.Select(expr,
relationship.LinkFromIDColumn, DataViewRowState.Unchanged);
rows[0].Delete();
According to all of the ADO.NET references I have seen, this does not
physically remove the data from the dataset, but simply marks its RowState
as deleted. And true to its word, when I interogate it in the quick-watch
window, it is marked as deleted.
Later in the session, I want to update the database to reflected the deleted
row. This is done as follows:
... Method Name ..
curTable = this.dataSet.Tables[relationship.TableName];
curAdapter = new OleDbDataAdapter();
OleDbCommand deleteCmd = this.deleteRelationshipCmds[0];
deleteCmd.Connection = oleDbConnection;
deleteCmd.Transaction = dbTransaction;
curAdapter.DeleteCommand = deleteCmd;
DataView relationshipView = new DataView(curTable, "", "",
DataViewRowState.Deleted);
IEnumerator enumRelationships = relationshipView.GetEnumerator();
while (enumRelationships.MoveNext() && !bAbort)
{
DataRowView curRelationshipView = (DataRowView) enumRelationships.Current;
objUpdateRows[0] = curRelationshipView.Row;
try
{
if(objUpdateRows[0].RowState == DataRowState.Deleted)
{
curAdapter.DeleteCommand.Parameters.Add(relationship.Name,
objUpdateRows[0][relationship.Name, DataRowVersion.Original]);
curAdapter.DeleteCommand.Parameters.Add(relationship.LinkFromIDColumn,
objUpdateRows[0][relationship.LinkFromIDColumn, DataRowVersion.Original]);
curAdapter.DeleteCommand.Parameters.Add(relationship.LinkToIDColumn,
objUpdateRows[0][relationship.LinkToIDColumn, DataRowVersion.Original]);
}
rowCount += curAdapter.Update(objUpdateRows);
}
catch { ... }
}
The building of the delete statement is done like this:
private static OleDbCommand
GenerateDeleteCommand(Elsinore.Engine.ClassRelationship objRelationship)
{
OleDbCommand cmd = null;
if (objRelationship != null)
{
string relationshipTableName = objRelationship.TableName;
if (relationshipTableName != null && relationshipTableName.Length > 0)
{
if (objRelationship.TableName == "Object_Objects")
{
string sqlText = "DELETE FROM " + Constants.DbOwner +
Constants.DbEscapePrefix + Constants.DbNamePrefix +
objRelationship.TableName + Constants.DbEscapeSuffix;
sqlText += " WHERE RelationshipName=? AND LinkFromID=? AND LinkToID=?";
cmd = new OleDbCommand(sqlText);
cmd.Parameters.Add("@p1", OleDbType.Char, 64, "RelationshipName");
cmd.Parameters.Add("@p2", OleDbType.Guid, 16, "LinkFromID");
cmd.Parameters.Add("@p3", OleDbType.Guid, 16, "LinkToID");
}
}
}
return cmd;
}
So, what I want to do is during the OleDBAdapter.Update call, is remove the
rows that are marked as Deleted. Since the current version of the Row's
ItemsArray is inaccessible (I assume because it is marked as deleted), then
I ask each column in the row to return me the original version of the data
for which I can manually add as parameters to my delete command.
Alas, this does not work, the original version of the row does not support
access to the items array. So, does anyone have a suggestion about this
problem that they could share with me? Thanks in advance.
Scott
I have a read only list view that is populated with information from a
dataset. If the user selects a listview item and presses the delete button,
then the item is removed fromt he list, and the underlying dataset is marked
as delete (all conditional and error checking has been removed for this
post):
expr = "RelationshipName ='" + relationshipName + "' AND LinkFromID = '" +
linkFromID + "' AND LinkToID = '" + linkToID + "'";
DataRow[] rows = this.objectObjectsTable.Select(expr,
relationship.LinkFromIDColumn, DataViewRowState.Unchanged);
rows[0].Delete();
According to all of the ADO.NET references I have seen, this does not
physically remove the data from the dataset, but simply marks its RowState
as deleted. And true to its word, when I interogate it in the quick-watch
window, it is marked as deleted.
Later in the session, I want to update the database to reflected the deleted
row. This is done as follows:
... Method Name ..
curTable = this.dataSet.Tables[relationship.TableName];
curAdapter = new OleDbDataAdapter();
OleDbCommand deleteCmd = this.deleteRelationshipCmds[0];
deleteCmd.Connection = oleDbConnection;
deleteCmd.Transaction = dbTransaction;
curAdapter.DeleteCommand = deleteCmd;
DataView relationshipView = new DataView(curTable, "", "",
DataViewRowState.Deleted);
IEnumerator enumRelationships = relationshipView.GetEnumerator();
while (enumRelationships.MoveNext() && !bAbort)
{
DataRowView curRelationshipView = (DataRowView) enumRelationships.Current;
objUpdateRows[0] = curRelationshipView.Row;
try
{
if(objUpdateRows[0].RowState == DataRowState.Deleted)
{
curAdapter.DeleteCommand.Parameters.Add(relationship.Name,
objUpdateRows[0][relationship.Name, DataRowVersion.Original]);
curAdapter.DeleteCommand.Parameters.Add(relationship.LinkFromIDColumn,
objUpdateRows[0][relationship.LinkFromIDColumn, DataRowVersion.Original]);
curAdapter.DeleteCommand.Parameters.Add(relationship.LinkToIDColumn,
objUpdateRows[0][relationship.LinkToIDColumn, DataRowVersion.Original]);
}
rowCount += curAdapter.Update(objUpdateRows);
}
catch { ... }
}
The building of the delete statement is done like this:
private static OleDbCommand
GenerateDeleteCommand(Elsinore.Engine.ClassRelationship objRelationship)
{
OleDbCommand cmd = null;
if (objRelationship != null)
{
string relationshipTableName = objRelationship.TableName;
if (relationshipTableName != null && relationshipTableName.Length > 0)
{
if (objRelationship.TableName == "Object_Objects")
{
string sqlText = "DELETE FROM " + Constants.DbOwner +
Constants.DbEscapePrefix + Constants.DbNamePrefix +
objRelationship.TableName + Constants.DbEscapeSuffix;
sqlText += " WHERE RelationshipName=? AND LinkFromID=? AND LinkToID=?";
cmd = new OleDbCommand(sqlText);
cmd.Parameters.Add("@p1", OleDbType.Char, 64, "RelationshipName");
cmd.Parameters.Add("@p2", OleDbType.Guid, 16, "LinkFromID");
cmd.Parameters.Add("@p3", OleDbType.Guid, 16, "LinkToID");
}
}
}
return cmd;
}
So, what I want to do is during the OleDBAdapter.Update call, is remove the
rows that are marked as Deleted. Since the current version of the Row's
ItemsArray is inaccessible (I assume because it is marked as deleted), then
I ask each column in the row to return me the original version of the data
for which I can manually add as parameters to my delete command.
Alas, this does not work, the original version of the row does not support
access to the items array. So, does anyone have a suggestion about this
problem that they could share with me? Thanks in advance.
Scott