Solved

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

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

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…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

624 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