Solved

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

Posted on 2009-05-08
4
660 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

912 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now