Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

what exactly datarow[] is? what an item is?

Posted on 2009-05-08
4
Medium Priority
?
670 Views
Last Modified: 2012-05-06
Hello:

Fields in  a data row can be accessed by using what seems to be an index: mydatarow[mycolum]

But, what exactly [] is? What I don't understand is that if it is a C# index, as it seems to be, how are the various possible column data types managed?

Until I know, a C# index returns the same data type for all the elements in the collection, but columns in a row are likely to be of different data types. So, how an index can be used to return the values of the different columns?

Additionally, what is the "item" property? It seem to be relatd to it.

Thanks in advance,

Juarrero
0
Comment
Question by:juarrero
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 1

Assisted Solution

by:Acumentality
Acumentality earned 225 total points
ID: 24335322
datarow[] returns an object of type Object. All Types inherit from Object.

datarow item property : http://msdn.microsoft.com/en-us/library/aa325577(VS.71).aspx
"Gets or sets the data stored in the column specified by index."
0
 
LVL 9

Accepted Solution

by:
tculler earned 525 total points
ID: 24336236
The "[]" operator is just an indexing operator. You can actually supply (and even overload) your own in a custom class, if you want.

As the guy above me said, ALL types inherit from Object. Because of this, they can all be "up-cast" back to an object.

However, when it comes to DataRow objects, the types are all the same, because that's how they are managed in C#. Their data is stored in the format it was when pulled from the DB (as a String, a number, date, etc.), but accessing it allows you to interact with it as any data type (it will convert the type to the desired type).

A DataRow should really be called a Record, because that's the "proper" term for DB talk. It is a single row of one or more columns (usually more than 1), which is why the "item" property is included. The "Item" property returns one of these columns (more commonly known as "Fields") based on an argument you pass it. The designers overload the indexers to provide mroe flexibility--you may either supply the name of the field you wish to get, or the ordinal number (the "number" of the row, 0-based I believe).

Hope that helped,
Nate
0
 

Author Comment

by:juarrero
ID: 24677086
Hello:

Before closing the question, I would like to post this link, what I think may be useful for understanding a bit more the internals of C#.

   http://forums.asp.net/t/1332378.aspx

Thanks,

Juarrero
0
 

Author Closing Comment

by:juarrero
ID: 31579392
A bit more information regarding the item property (see the link I posted) would have been nice.

Thanks to you both.

Juarrero
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question