syntax for Dataview vs. Dataset

dalem

Member
Joined
Apr 11, 2005
Messages
17
Programming Experience
10+
I have recently discovered a problem with some code I have been using. In the past, when I wanted to get a value of some item of some row within a dataview, I used the following syntax:

CurrentDataview.Table.Rows(RowNumberOfInterest).Item("PreviewCaption")
with the variable RowNumberOfInterest being the integer representing the row number of the dataview I wanted and "PreviewCaption" being the bound field name–

this seemed to work correctly and there were no syntax errors from the VS IDE, so I thought this was appropriate–besides, it was similar to code that I’ve used for datasets all along.

However, from time to time, I had unexplained results and eventually traced it back to this syntax.

After some research, I discovered the appropriate syntax seems to be the following:

CurrentDataview(CurrentPosition).Item("PreviewCaption")–just remove the Table.rows segment. This seems to correct the problems I was getting with the first version.

Am I the only one who confused this–is there any other background I should know–is the first syntax ever appropriate?

Thanks for any feedback and insight anyone can give me.

dale
 
a little more info

thanks for replying

typically, i use the dataview as the datasource for a control that the user has made a selection from (i.e. drop down list or list box) and i use the position or index of the selection from the control to then go to the dataview and retrieve other values for the row that the item selected is bound to

like i said, until recently, i had used the same basic syntax for this in dataviews as i did for datasets (dataview.table.rows(position).item(fieldname) to access the appropriate row in the dataview

but now i have switched to the syntax of dataview(position).item(fieldname) to access the row.

Here are the 2 statements in question (say i want to access the 10th row of the "AssessementDataView" to get a value of an item in that row).

Dim CurrentValue As String = AssessmentSummaryDataview.Table.Rows(9).Item("AssessType")

Dim CurrentValue as String= AssessmentSummaryDataview(9).Item("AssessType")

The first statement, which i always assumed was the correct one, i have found to give the desired results most of the time but in some cases it does not (am still tryinig to determine why and under what circumstances). The 2nd statement (which i found after some digging) seems to always give the desired result in my limited testing of when statement 1 fails. it apparently also gives the desired result when statement 1 does not fail.

the VS IDE permits either to be used without syntax error and gives similar but not identical inteligence blurb for both. In the first case, the IDE intellisense blurb says "Zero based index of the row to return" while the 2nd statement says "The index of a record in the System.Data.DataTable"

I am using 2003--this might be a bug or more likely, maybe i don't understand the difference between the two statements and have been using it incorrectly all this time.

thanks

dale
 
Might it be the case that one doesnt support the notion of a sorted data model? i.e. if you have the letters of the alphabet in random order in the data model, but have sorted the datagrid, one method may give you "Q" when you ask for row 0, the other method gives you "A"

If you want to see the code, i believe you can use a tool called Reflector, though I'm not sure how to use it to look at the code of the .NET framework. The last time I knew of its use, J McIlhinney had used it to answer a question I had. In this particular case I can tell you that:

AssessmentSummaryDataview(9).Item("AssessType")


AssessmentSummaryDataview has a Default Property that maps to something and does some code - take a look at the code for the default property of an AssessmentSummaryDataview and you will see (maybe) why it differs
 
yes, you might be on to something--that could be the difference--maybe that's why i haven't detected the difference until now. but i've searched various books and documents and can't find any reference to it.

thanks for the suggestion.

dale
 
Back
Top