Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > name-based referencing of collection members?

Reply
Thread Tools

name-based referencing of collection members?

 
 
K. Shier
Guest
Posts: n/a
 
      10-01-2003
is it a thing of the past?

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

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! =)


 
Reply With Quote
 
 
 
 
Jay B. Harlow [MVP - Outlook]
Guest
Posts: n/a
 
      10-02-2003
K. Shier,
> i miss being able to write code like:
> DataSet.Tables("MyTableName").Columns("MyColumnNam e")
>

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. Shier" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> is it a thing of the past?
>
> i miss being able to write code like:
> DataSet.Tables("MyTableName").Columns("MyColumnNam e")
>
> 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! =)
>
>



 
Reply With Quote
 
 
 
 
K. Shier
Guest
Posts: n/a
 
      10-03-2003
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! =)

"Jay B. Harlow [MVP - Outlook]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> K. Shier,
> > i miss being able to write code like:
> > DataSet.Tables("MyTableName").Columns("MyColumnNam e")
> >

> 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. Shier" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
> > is it a thing of the past?
> >
> > i miss being able to write code like:
> > DataSet.Tables("MyTableName").Columns("MyColumnNam e")
> >
> > 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! =)
> >
> >

>
>



 
Reply With Quote
 
Jay B. Harlow [MVP - Outlook]
Guest
Posts: n/a
 
      10-03-2003
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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! =)
>
> "Jay B. Harlow [MVP - Outlook]" <(E-Mail Removed)> wrote in

message
> news:(E-Mail Removed)...
> > K. Shier,
> > > i miss being able to write code like:
> > > DataSet.Tables("MyTableName").Columns("MyColumnNam e")
> > >

> > 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. Shier" <(E-Mail Removed)> wrote in message
> > news:%(E-Mail Removed)...
> > > is it a thing of the past?
> > >
> > > i miss being able to write code like:
> > > DataSet.Tables("MyTableName").Columns("MyColumnNam e")
> > >
> > > 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! =)
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
K. Shier
Guest
Posts: n/a
 
      10-08-2003
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 [MVP - Outlook]" <(E-Mail Removed)> wrote in message
news:Oa857#(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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! =)
> >
> > "Jay B. Harlow [MVP - Outlook]" <(E-Mail Removed)> wrote in

> message
> > news:(E-Mail Removed)...
> > > K. Shier,
> > > > i miss being able to write code like:
> > > > DataSet.Tables("MyTableName").Columns("MyColumnNam e")
> > > >
> > > 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. Shier" <(E-Mail Removed)> wrote in message
> > > news:%(E-Mail Removed)...
> > > > is it a thing of the past?
> > > >
> > > > i miss being able to write code like:
> > > > DataSet.Tables("MyTableName").Columns("MyColumnNam e")
> > > >
> > > > 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! =)
> > > >
> > > >
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Jay B. Harlow [MVP - Outlook]
Guest
Posts: n/a
 
      10-09-2003
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" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> 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 [MVP - Outlook]" <(E-Mail Removed)> wrote in

message
> news:Oa857#(E-Mail Removed)...
> > 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" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > 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! =)
> > >
> > > "Jay B. Harlow [MVP - Outlook]" <(E-Mail Removed)> wrote in

> > message
> > > news:(E-Mail Removed)...
> > > > K. Shier,
> > > > > i miss being able to write code like:
> > > > > DataSet.Tables("MyTableName").Columns("MyColumnNam e")
> > > > >
> > > > 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. Shier" <(E-Mail Removed)> wrote in message
> > > > news:%(E-Mail Removed)...
> > > > > is it a thing of the past?
> > > > >
> > > > > i miss being able to write code like:
> > > > > DataSet.Tables("MyTableName").Columns("MyColumnNam e")
> > > > >
> > > > > 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! =)
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >

> >
> >

>
>




 
Reply With Quote
 
K. Shier
Guest
Posts: n/a
 
      10-10-2003
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 [MVP - Outlook]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
> > 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 [MVP - Outlook]" <(E-Mail Removed)> wrote in

> message
> > news:Oa857#(E-Mail Removed)...
> > > 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" <(E-Mail Removed)> wrote in message
> > > news:(E-Mail Removed)...
> > > > 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! =)
> > > >
> > > > "Jay B. Harlow [MVP - Outlook]" <(E-Mail Removed)> wrote in
> > > message
> > > > news:(E-Mail Removed)...
> > > > > K. Shier,
> > > > > > i miss being able to write code like:
> > > > > > DataSet.Tables("MyTableName").Columns("MyColumnNam e")
> > > > > >
> > > > > 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. Shier" <(E-Mail Removed)> wrote in message
> > > > > news:%(E-Mail Removed)...
> > > > > > is it a thing of the past?
> > > > > >
> > > > > > i miss being able to write code like:
> > > > > > DataSet.Tables("MyTableName").Columns("MyColumnNam e")
> > > > > >
> > > > > > 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! =)
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >

> >
> >

>
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
create collection of collection Hemant ASP .Net 1 10-22-2009 03:04 PM
Collection problems (create Collection object, add data to collection, bind collection to datagrid) Řyvind Isaksen ASP .Net 1 05-18-2007 09:24 AM
Sorting the Collection(java.util.Collection) of Elements Pradeep Java 2 01-24-2007 02:33 PM
Adding to collection from controlDesigner only produces end tag for the collection. Don ASP .Net Building Controls 0 07-22-2005 09:31 PM
STL - an algorithm for finding a collection within a collection? Dylan C++ 5 03-22-2005 01:31 AM



Advertisments