Confused about DataRowVersion.Default

S

Steve

From MSDN on DataRowVersion.Default:

"The row the default version for the current DataRowState. For a
DataRowState value of Added, Modified or Current, the default version is
Current. For a DataRowState of Deleted, the version is Original. For a
DataRowState value of Detached, the version is Proposed."

Reading the above, I would assume that this code:

/////
ReturnValue = MyDataRow[ "MyFieldName", DataRowVersion.Default ];
/////

Should be equivalent to this code:

/////
if ( MyDataRow.RowState == DataRowState.Deleted ) {
ReturnValue = MyDataRow[ "MyFieldName", DataRowVersion.Original ];
} else {
ReturnValue = MyDataRow[ "MyFieldName", DataRowVersion.Current ];
}
/////

However, the first block of code throws DeletedRowInaccessibleException
while the second one works just fine. Am I reading the documentation wrong?
What am I missing?

Thanks,
-Steve
 
M

Miha Markic [MVP C#]

Hi Steve,

You are right - it won't work for deleted rows.
I guess the documentation is wrong at this point.
You should use DataRowVersion.Original explicitly to get data out of a
deleted row.
 
S

Steve

Anyone know the URL/email for reporting errors in the documentation?

-Steve


Miha Markic said:
Hi Steve,

You are right - it won't work for deleted rows.
I guess the documentation is wrong at this point.
You should use DataRowVersion.Original explicitly to get data out of a
deleted row.

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

Steve said:
From MSDN on DataRowVersion.Default:

"The row the default version for the current DataRowState. For a
DataRowState value of Added, Modified or Current, the default version is
Current. For a DataRowState of Deleted, the version is Original. For a
DataRowState value of Detached, the version is Proposed."

Reading the above, I would assume that this code:

/////
ReturnValue = MyDataRow[ "MyFieldName", DataRowVersion.Default ];
/////

Should be equivalent to this code:

/////
if ( MyDataRow.RowState == DataRowState.Deleted ) {
ReturnValue = MyDataRow[ "MyFieldName", DataRowVersion.Original ];
} else {
ReturnValue = MyDataRow[ "MyFieldName", DataRowVersion.Current ];
}
/////

However, the first block of code throws DeletedRowInaccessibleException
while the second one works just fine. Am I reading the documentation wrong?
What am I missing?

Thanks,
-Steve
 
J

Jon Skeet [C# MVP]

Steve said:
Anyone know the URL/email for reporting errors in the documentation?

At the bottom of each MSDN page is a link. I've found the feedback to
be very good - once I reported one particular bug in some sample code,
and got a reply fairly quickly saying that the original code had all
*kinds* of bugs in once you got into it, and that he'd now completely
rewritten it. Great stuff.
 
K

Kevin Yu [MSFT]

Hi Steve,

Thank you for posting in the community!

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that the DataRowVersion.Default doesn't work
as the document states. If there is any misunderstanding, please feel free
to let me know.

This seems to be a known issue of the document. I have sent a feedback to
the corresponding team. It will be fixed after they confirm this. Thank you
very much for your feedback!

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top