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
Solved

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

Posted on 2009-05-08
4
664 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
  • 2
4 Comments
 
LVL 1

Assisted Solution

by:Acumentality
Acumentality earned 75 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 175 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

856 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