name-based referencing of collection members?

K

K. Shier

is it a thing of the past?

i miss being able to write code like:
DataSet.Tables("MyTableName").Columns("MyColumnName")

now i have to use integer-based indexes like: DataSet.Tables(0).Columns(0)

i thought 'instinctive implementation' and 'easily readable code' were
supposed to be design hallmarks of R.A.D.?

I _can_ manage everything this way, but i shouldn't _HAVE TO_! how do you
do it 'the old way' in VB.Net?

also, anyone have a link to an article explaining why i shouldn't flame M$
for this seemingly de-evolutionary design change?

help a newbie out! =)
 
J

Jay B. Harlow [MVP - Outlook]

K. Shier,
i miss being able to write code like:
DataSet.Tables("MyTableName").Columns("MyColumnName")
I believe you are confused! the above is fully supported! To a degree
greater than VB6. In that you can change the name in the dataset from what
it is in your database or select statement!

DataTableCollection (the object returned from DataSet.Tables property)
supports indexing by String and so does DataColumnCollection (the object
returned from DataTable.Columns property)

What specifically is the error you are seeing?

Are you certain that you are populating the DataSet with correctly named
tables & columns?

Can you post the code you use to create the DataSet, along with how you
populate it and how you are trying to retrieve the data?

David Sceppa's book "Microsoft ADO.NET - Core Reference" from MS Press fully
explains how to build your DataSet objects so they fully support indexing by
strings.

Hope this helps
Jay
 
K

K. Shier

you are correct. i _am_ confused. (in more ways than this, even! =) )

the example i gave was bad. i was able to disprove it myself shortly
thereafter. (it was also purely theoretical - i'm not having any problems
with datasets right this second... [looks around for wood to knock on])

but i could swear i have seen the problem before.... trying to reference a
member of some collection by name (string) results in "Invalid Cast
Exception - type 'String' can't be cast to type 'Integer'" (paraphrased, but
you get the idea)

if i come across it again i'll post back. anyway thanks for the sanity
check! =)
 
J

Jay B. Harlow [MVP - Outlook]

K. Shier,
but i could swear i have seen the problem before.... trying to reference a
member of some collection by name (string) results in "Invalid Cast

There are a number of collection classes in .NET that you cannot index by
string!

ArrayList & CollectionBase for example are collections that you cannot index
by a String.

Its just that DataSet is not one of them. :)

Hope this helps
Jay

K. Shier said:
you are correct. i _am_ confused. (in more ways than this, even! =) )

the example i gave was bad. i was able to disprove it myself shortly
thereafter. (it was also purely theoretical - i'm not having any problems
with datasets right this second... [looks around for wood to knock on])

but i could swear i have seen the problem before.... trying to reference a
member of some collection by name (string) results in "Invalid Cast
Exception - type 'String' can't be cast to type 'Integer'" (paraphrased, but
you get the idea)

if i come across it again i'll post back. anyway thanks for the sanity
check! =)

K. Shier,
I believe you are confused! the above is fully supported! To a degree
greater than VB6. In that you can change the name in the dataset from what
it is in your database or select statement!

DataTableCollection (the object returned from DataSet.Tables property)
supports indexing by String and so does DataColumnCollection (the object
returned from DataTable.Columns property)

What specifically is the error you are seeing?

Are you certain that you are populating the DataSet with correctly named
tables & columns?

Can you post the code you use to create the DataSet, along with how you
populate it and how you are trying to retrieve the data?

David Sceppa's book "Microsoft ADO.NET - Core Reference" from MS Press fully
explains how to build your DataSet objects so they fully support
indexing
by
strings.

Hope this helps
Jay
flame
 
K

K. Shier

it could be that i ran into this problem with one of these other collection
types and mistakenly thought it worked that way with all collections.

does reference by string still work (in classes which support it) when
Option Strict is On?

Jay B. Harlow said:
K. Shier,
but i could swear i have seen the problem before.... trying to
reference
a
member of some collection by name (string) results in "Invalid Cast

There are a number of collection classes in .NET that you cannot index by
string!

ArrayList & CollectionBase for example are collections that you cannot index
by a String.

Its just that DataSet is not one of them. :)

Hope this helps
Jay

K. Shier said:
you are correct. i _am_ confused. (in more ways than this, even! =) )

the example i gave was bad. i was able to disprove it myself shortly
thereafter. (it was also purely theoretical - i'm not having any problems
with datasets right this second... [looks around for wood to knock on])

but i could swear i have seen the problem before.... trying to
reference
a
member of some collection by name (string) results in "Invalid Cast
Exception - type 'String' can't be cast to type 'Integer'" (paraphrased, but
you get the idea)

if i come across it again i'll post back. anyway thanks for the sanity
check! =)

indexing do
you flame
 
J

Jay B. Harlow [MVP - Outlook]

K.Shier,
does reference by string still work (in classes which support it) when
Option Strict is On?
Yes. The nice thing about Option Strict On is you will receive a compile
error if you attempt to index by an object that indexing is not supported,
as opposed to getting a runtime error, which may be harder to track down.

Hope this helps
Jay

K. Shier said:
it could be that i ran into this problem with one of these other collection
types and mistakenly thought it worked that way with all collections.

does reference by string still work (in classes which support it) when
Option Strict is On?

K. Shier,
but i could swear i have seen the problem before.... trying to
reference
a
member of some collection by name (string) results in "Invalid Cast

There are a number of collection classes in .NET that you cannot index by
string!

ArrayList & CollectionBase for example are collections that you cannot index
by a String.

Its just that DataSet is not one of them. :)

Hope this helps
Jay

K. Shier said:
you are correct. i _am_ confused. (in more ways than this, even! =) )

the example i gave was bad. i was able to disprove it myself shortly
thereafter. (it was also purely theoretical - i'm not having any problems
with datasets right this second... [looks around for wood to knock on])

but i could swear i have seen the problem before.... trying to
reference
a
member of some collection by name (string) results in "Invalid Cast
Exception - type 'String' can't be cast to type 'Integer'"
(paraphrased,
but
you get the idea)

if i come across it again i'll post back. anyway thanks for the sanity
check! =)

K. Shier,
i miss being able to write code like:
DataSet.Tables("MyTableName").Columns("MyColumnName")

I believe you are confused! the above is fully supported! To a degree
greater than VB6. In that you can change the name in the dataset
from
what
it is in your database or select statement!

DataTableCollection (the object returned from DataSet.Tables property)
supports indexing by String and so does DataColumnCollection (the object
returned from DataTable.Columns property)

What specifically is the error you are seeing?

Are you certain that you are populating the DataSet with correctly named
tables & columns?

Can you post the code you use to create the DataSet, along with how you
populate it and how you are trying to retrieve the data?

David Sceppa's book "Microsoft ADO.NET - Core Reference" from MS Press
fully
explains how to build your DataSet objects so they fully support indexing
by
strings.

Hope this helps
Jay

is it a thing of the past?

i miss being able to write code like:
DataSet.Tables("MyTableName").Columns("MyColumnName")

now i have to use integer-based indexes like:
DataSet.Tables(0).Columns(0)

i thought 'instinctive implementation' and 'easily readable code' were
supposed to be design hallmarks of R.A.D.?

I _can_ manage everything this way, but i shouldn't _HAVE TO_!
how
 
K

K. Shier

hmm well i thought Option Strict On might have been the cause of the
problem, but it must have just been that i was trying to do it in a
collection class that doesn't support it.

i probably came under this assumption back in my very early days of .Net,
when i was largely oblivious to any differences from .Old. at this point i
am trying to re-reckon everything i have learned in the past 3-4 months and
get a better handle on it.

so thanks for helping me clear this up! =)

Jay B. Harlow said:
K.Shier,
does reference by string still work (in classes which support it) when
Option Strict is On?
Yes. The nice thing about Option Strict On is you will receive a compile
error if you attempt to index by an object that indexing is not supported,
as opposed to getting a runtime error, which may be harder to track down.

Hope this helps
Jay

K. Shier said:
it could be that i ran into this problem with one of these other collection
types and mistakenly thought it worked that way with all collections.

does reference by string still work (in classes which support it) when
Option Strict is On?

K. Shier,
but i could swear i have seen the problem before.... trying to reference
a
member of some collection by name (string) results in "Invalid Cast

There are a number of collection classes in .NET that you cannot index by
string!

ArrayList & CollectionBase for example are collections that you cannot index
by a String.

Its just that DataSet is not one of them. :)

Hope this helps
Jay

you are correct. i _am_ confused. (in more ways than this, even! =) )

the example i gave was bad. i was able to disprove it myself shortly
thereafter. (it was also purely theoretical - i'm not having any problems
with datasets right this second... [looks around for wood to knock on])

but i could swear i have seen the problem before.... trying to reference
a
member of some collection by name (string) results in "Invalid Cast
Exception - type 'String' can't be cast to type 'Integer'" (paraphrased,
but
you get the idea)

if i come across it again i'll post back. anyway thanks for the sanity
check! =)

message
K. Shier,
i miss being able to write code like:
DataSet.Tables("MyTableName").Columns("MyColumnName")

I believe you are confused! the above is fully supported! To a degree
greater than VB6. In that you can change the name in the dataset from
what
it is in your database or select statement!

DataTableCollection (the object returned from DataSet.Tables property)
supports indexing by String and so does DataColumnCollection (the object
returned from DataTable.Columns property)

What specifically is the error you are seeing?

Are you certain that you are populating the DataSet with correctly named
tables & columns?

Can you post the code you use to create the DataSet, along with
how
you
populate it and how you are trying to retrieve the data?

David Sceppa's book "Microsoft ADO.NET - Core Reference" from MS Press
fully
explains how to build your DataSet objects so they fully support
indexing
by
strings.

Hope this helps
Jay

is it a thing of the past?

i miss being able to write code like:
DataSet.Tables("MyTableName").Columns("MyColumnName")

now i have to use integer-based indexes like:
DataSet.Tables(0).Columns(0)

i thought 'instinctive implementation' and 'easily readable
code'
were
supposed to be design hallmarks of R.A.D.?

I _can_ manage everything this way, but i shouldn't _HAVE TO_!
how
do
you
do it 'the old way' in VB.Net?

also, anyone have a link to an article explaining why i shouldn't
flame
M$
for this seemingly de-evolutionary design change?

help a newbie out! =)
 

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top