Solved

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

Posted on 2009-05-08
4
658 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

772 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

8 Experts available now in Live!

Get 1:1 Help Now