name-based referencing of collection members?

Discussion in 'ASP .Net' started by K. Shier, Oct 1, 2003.

  1. K. Shier

    K. Shier Guest

    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! =)
    K. Shier, Oct 1, 2003
    #1
    1. Advertising

  2. 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. Shier" <> wrote in message
    news:%...
    > 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! =)
    >
    >
    Jay B. Harlow [MVP - Outlook], Oct 2, 2003
    #2
    1. Advertising

  3. K. Shier

    K. Shier Guest

    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]" <> wrote in message
    news:...
    > 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. Shier" <> wrote in message
    > news:%...
    > > 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! =)
    > >
    > >

    >
    >
    K. Shier, Oct 3, 2003
    #3
  4. 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" <> wrote in message
    news:...
    > 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]" <> wrote in

    message
    > news:...
    > > 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. Shier" <> wrote in message
    > > news:%...
    > > > 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! =)
    > > >
    > > >

    > >
    > >

    >
    >
    Jay B. Harlow [MVP - Outlook], Oct 3, 2003
    #4
  5. K. Shier

    K. Shier Guest

    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]" <> wrote in message
    news:Oa857#...
    > 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" <> wrote in message
    > news:...
    > > 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]" <> wrote in

    > message
    > > news:...
    > > > 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. Shier" <> wrote in message
    > > > news:%...
    > > > > 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! =)
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
    K. Shier, Oct 8, 2003
    #5
  6. 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" <> wrote in message
    news:%...
    > 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]" <> wrote in

    message
    > news:Oa857#...
    > > 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" <> wrote in message
    > > news:...
    > > > 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]" <> wrote in

    > > message
    > > > news:...
    > > > > 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. Shier" <> wrote in message
    > > > > news:%...
    > > > > > 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! =)
    > > > > >
    > > > > >
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
    Jay B. Harlow [MVP - Outlook], Oct 9, 2003
    #6
  7. K. Shier

    K. Shier Guest

    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]" <> wrote in message
    news:...
    > 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" <> wrote in message
    > news:%...
    > > 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]" <> wrote in

    > message
    > > news:Oa857#...
    > > > 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" <> wrote in message
    > > > news:...
    > > > > 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]" <> wrote in
    > > > message
    > > > > news:...
    > > > > > 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. Shier" <> wrote in message
    > > > > > news:%...
    > > > > > > 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! =)
    > > > > > >
    > > > > > >
    > > > > >
    > > > > >
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
    >
    K. Shier, Oct 10, 2003
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JFCM
    Replies:
    4
    Views:
    5,734
  2. ding feng
    Replies:
    2
    Views:
    2,804
    ding feng
    Jun 25, 2003
  3. CoolPint
    Replies:
    8
    Views:
    975
    Jeff Schwab
    Dec 14, 2003
  4. Asfand Yar Qazi
    Replies:
    7
    Views:
    326
    Asfand Yar Qazi
    Mar 25, 2005
  5. Øyvind Isaksen
    Replies:
    1
    Views:
    964
    Øyvind Isaksen
    May 18, 2007
Loading...

Share This Page