|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Index column in Dataset (or Datareader) !!!!When I put the a Select command result into a dataset (or datareader), I have
to inform which column index I want to work with...thats pretty akward , since I have to know in advance exactly the order the column appears in Select command. It gets complicated if we r talking of 30 columns. In ancient VB, I would use Enums to help in this, is there any intelligent way in .NET to solve this topic? Thanks to all ! Bruce - I'm not sure I follow you. Are you talking about the Sql Statement
you're firing against the db or datatable.select/ B/c you mention a reader I'm guessing it's the latter. If so, I'd first caution you about using 30 columns. Unless you really need all of them, just pull back what you need b/c there is overhead. What do you need the index for client side though? ARe you talking about query hints of some sort or is it something else? Perhaps if you can tell me a little more about the scenario I can be more helpful. Show quote "Bruce One" <r***@virtualsoftware.com.br> wrote in message news:76A566F8-FCDB-4D35-98E3-ACF03CA9DD92@microsoft.com... > When I put the a Select command result into a dataset (or datareader), I > have > to inform which column index I want to work with...thats pretty akward , > since I have to know in advance exactly the order the column appears in > Select command. It gets complicated if we r talking of 30 columns. In > ancient > VB, I would use Enums to help in this, is there any intelligent way in > .NET > to solve this topic? > > Thanks to all ! I agree 30 columns in a Select is too much. But lets consider 5 columns then.
I have 2 options: 1) by knowing column names, I would refer to them explcitily in dataset/datareader. 2) I would use index to refer to them. Is 1st case, I would have to memorize column names (or have them written down in some paper). In 2nd case, I would have to memorize column position in Select command. Show quote "W.G. Ryan eMVP" wrote: > Bruce - I'm not sure I follow you. Are you talking about the Sql Statement > you're firing against the db or datatable.select/ B/c you mention a reader > I'm guessing it's the latter. If so, I'd first caution you about using 30 > columns. Unless you really need all of them, just pull back what you need > b/c there is overhead. What do you need the index for client side though? > ARe you talking about query hints of some sort or is it something else? > Perhaps if you can tell me a little more about the scenario I can be more > helpful. > "Bruce One" <r***@virtualsoftware.com.br> wrote in message > news:76A566F8-FCDB-4D35-98E3-ACF03CA9DD92@microsoft.com... > > When I put the a Select command result into a dataset (or datareader), I > > have > > to inform which column index I want to work with...thats pretty akward , > > since I have to know in advance exactly the order the column appears in > > Select command. It gets complicated if we r talking of 30 columns. In > > ancient > > VB, I would use Enums to help in this, is there any intelligent way in > > .NET > > to solve this topic? > > > > Thanks to all ! > > > YOu can use typed datasets which will fix this for you via intellisense. THe
other case, as the illustrious Bill Vaughn recommends, is creating an enumeration corresponding to the column indexes. This gives you column names via intellisense and the performance of index based lookups. Show quote "Bruce One" <r***@virtualsoftware.com.br> wrote in message news:4DF793A7-FD74-439A-A3FC-B10677BA1816@microsoft.com... >I agree 30 columns in a Select is too much. But lets consider 5 columns >then. > I have 2 options: 1) by knowing column names, I would refer to them > explcitily in dataset/datareader. 2) I would use index to refer to them. > > Is 1st case, I would have to memorize column names (or have them written > down in some paper). In 2nd case, I would have to memorize column position > in > Select command. > > "W.G. Ryan eMVP" wrote: > >> Bruce - I'm not sure I follow you. Are you talking about the Sql >> Statement >> you're firing against the db or datatable.select/ B/c you mention a >> reader >> I'm guessing it's the latter. If so, I'd first caution you about using >> 30 >> columns. Unless you really need all of them, just pull back what you need >> b/c there is overhead. What do you need the index for client side >> though? >> ARe you talking about query hints of some sort or is it something else? >> Perhaps if you can tell me a little more about the scenario I can be more >> helpful. >> "Bruce One" <r***@virtualsoftware.com.br> wrote in message >> news:76A566F8-FCDB-4D35-98E3-ACF03CA9DD92@microsoft.com... >> > When I put the a Select command result into a dataset (or datareader), >> > I >> > have >> > to inform which column index I want to work with...thats pretty akward >> > , >> > since I have to know in advance exactly the order the column appears in >> > Select command. It gets complicated if we r talking of 30 columns. In >> > ancient >> > VB, I would use Enums to help in this, is there any intelligent way in >> > .NET >> > to solve this topic? >> > >> > Thanks to all ! >> >> >> In most cases though- use a Typed dataset, this is the easiest approach.
When you use datareaders, use the enums. Show quote "Bruce One" <r***@virtualsoftware.com.br> wrote in message news:4DF793A7-FD74-439A-A3FC-B10677BA1816@microsoft.com... >I agree 30 columns in a Select is too much. But lets consider 5 columns >then. > I have 2 options: 1) by knowing column names, I would refer to them > explcitily in dataset/datareader. 2) I would use index to refer to them. > > Is 1st case, I would have to memorize column names (or have them written > down in some paper). In 2nd case, I would have to memorize column position > in > Select command. > > "W.G. Ryan eMVP" wrote: > >> Bruce - I'm not sure I follow you. Are you talking about the Sql >> Statement >> you're firing against the db or datatable.select/ B/c you mention a >> reader >> I'm guessing it's the latter. If so, I'd first caution you about using >> 30 >> columns. Unless you really need all of them, just pull back what you need >> b/c there is overhead. What do you need the index for client side >> though? >> ARe you talking about query hints of some sort or is it something else? >> Perhaps if you can tell me a little more about the scenario I can be more >> helpful. >> "Bruce One" <r***@virtualsoftware.com.br> wrote in message >> news:76A566F8-FCDB-4D35-98E3-ACF03CA9DD92@microsoft.com... >> > When I put the a Select command result into a dataset (or datareader), >> > I >> > have >> > to inform which column index I want to work with...thats pretty akward >> > , >> > since I have to know in advance exactly the order the column appears in >> > Select command. It gets complicated if we r talking of 30 columns. In >> > ancient >> > VB, I would use Enums to help in this, is there any intelligent way in >> > .NET >> > to solve this topic? >> > >> > Thanks to all ! >> >> >> Why can't you just refer to the column by the column name (which is taken
from the field name in the SQL statement)? Show quote "Bruce One" <r***@virtualsoftware.com.br> wrote in message news:76A566F8-FCDB-4D35-98E3-ACF03CA9DD92@microsoft.com... > When I put the a Select command result into a dataset (or datareader), I > have > to inform which column index I want to work with...thats pretty akward , > since I have to know in advance exactly the order the column appears in > Select command. It gets complicated if we r talking of 30 columns. In > ancient > VB, I would use Enums to help in this, is there any intelligent way in > .NET > to solve this topic? > > Thanks to all ! Because I would have to memorize its names...I thought I could create a
solution (like an intellisense browser) so that I wouldnt have to know column names or its position in Select command. In old VB I would solve this by using Enums.... Thanks! Show quote "Scott M." wrote: > Why can't you just refer to the column by the column name (which is taken > from the field name in the SQL statement)? > > > "Bruce One" <r***@virtualsoftware.com.br> wrote in message > news:76A566F8-FCDB-4D35-98E3-ACF03CA9DD92@microsoft.com... > > When I put the a Select command result into a dataset (or datareader), I > > have > > to inform which column index I want to work with...thats pretty akward , > > since I have to know in advance exactly the order the column appears in > > Select command. It gets complicated if we r talking of 30 columns. In > > ancient > > VB, I would use Enums to help in this, is there any intelligent way in > > .NET > > to solve this topic? > > > > Thanks to all ! > > > Then what about a strongly-typed dataset? This will list your table and
column names in the intellisense. Show quote "Bruce One" <r***@virtualsoftware.com.br> wrote in message news:B662E14D-CA41-498B-96B5-FB1136EB9BAF@microsoft.com... > Because I would have to memorize its names...I thought I could create a > solution (like an intellisense browser) so that I wouldnt have to know > column > names or its position in Select command. In old VB I would solve this by > using Enums.... > > Thanks! > > "Scott M." wrote: > >> Why can't you just refer to the column by the column name (which is taken >> from the field name in the SQL statement)? >> >> >> "Bruce One" <r***@virtualsoftware.com.br> wrote in message >> news:76A566F8-FCDB-4D35-98E3-ACF03CA9DD92@microsoft.com... >> > When I put the a Select command result into a dataset (or datareader), >> > I >> > have >> > to inform which column index I want to work with...thats pretty akward >> > , >> > since I have to know in advance exactly the order the column appears in >> > Select command. It gets complicated if we r talking of 30 columns. In >> > ancient >> > VB, I would use Enums to help in this, is there any intelligent way in >> > .NET >> > to solve this topic? >> > >> > Thanks to all ! >> >> >> Bruce,
You are talking about apples and pears as the same Datasets and datareader. The first one is a class that wraps around datatables and relation to store these, The second one is a active method to get data from a database. The first one is full of all kind of indexes. Can you explain for us more what you mean? Cor Show quote "Bruce One" <r***@virtualsoftware.com.br> schreef in bericht news:76A566F8-FCDB-4D35-98E3-ACF03CA9DD92@microsoft.com... > When I put the a Select command result into a dataset (or datareader), I > have > to inform which column index I want to work with...thats pretty akward , > since I have to know in advance exactly the order the column appears in > Select command. It gets complicated if we r talking of 30 columns. In > ancient > VB, I would use Enums to help in this, is there any intelligent way in > .NET > to solve this topic? > > Thanks to all ! |
|||||||||||||||||||||||