PC Review


Reply
Thread Tools Rate Thread

DataRow.Item

 
 
GaryDean
Guest
Posts: n/a
 
      29th Aug 2006
The docs say that the DataRow class has an Item property so I could set a
value without having to know the column name i.e. myDR.Item[0] = myString;

but, there is no Item property in the DataRow.

What am I not understanding?


--
Regards,
Gary Blakely


 
Reply With Quote
 
 
 
 
Karl Seguin [MVP]
Guest
Posts: n/a
 
      29th Aug 2006
It's a default property, which means you access it via indexes ([] in C#, ()
in VB.NET).

row[0] = myString;

Karl

--
http://www.openmymind.net/
http://www.codebetter.com/


"GaryDean" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> The docs say that the DataRow class has an Item property so I could set a
> value without having to know the column name i.e. myDR.Item[0] = myString;
>
> but, there is no Item property in the DataRow.
>
> What am I not understanding?
>
>
> --
> Regards,
> Gary Blakely
>
>



 
Reply With Quote
 
Walter Wang [MSFT]
Guest
Posts: n/a
 
      29th Aug 2006
Hi Gary,

In addition to normal parameterless properties, .NET programming languages
also support parameterful properties, whose get accessor methods accept one
or more parameters and whose set accessor methods accept two or more
parameters. Different programming languages expose parameterful properties
in different ways. Also, languages use different terms to refer to
parameterful properties: C# calls them indexers and Visual Basic calls them
default properties.

In C#, parameterful properties (indexers) are exposed using an array-like
syntax. In other words, you can think of an indexer as a way for the C#
developer to overload the [] operator.

Use BitArray for example:

public sealed class BitArray {

public Boolean this[Int32 bitPos] {
get {
...
}
set {
...
}
}

...
}

It's quite common to create an indexer to look up values in an associative
array. Unlike parameterless properties, a type can offer multiple,
overloaded indexers as long as their signatures differ.

The CLR internally emit either two or three following items into the
resulting managed assembly:

* A method representing the parameterful property's get accessor method.
This is emitted only if you define a get accessor method for the property.
* A method representing the parameterful property's set accessor method.
This is emitted only if you define a set accessor method for the property.
* A property definition in the managed assembly's metadata, which is
always emitted.

For the BitArray class shown above, the compiler compiles the indexer as
though the original source code were written as follows:

public sealed class BitArray {

public Boolean get_Item(Int32 bitPos) { ... }

public void set_Item(Int32 bitPos, Boolean value) { ... }

...
}

The compiler automatically generates names for these methods by prepending
get_ and set_ to the indexer name. Because the C# syntax for an indexer
doesn't allow the developer to specify an indexer name, the C# compiler
team had to choose a default name to use for the accessor methods; they
choose Item.

When examining the .NET Framework Reference documentation, you can tell if
a type offers an indexer by looking for a property named Item.

Therefore, the answer to your question is you can just use row[0] to access
the property.

Hope this helps. Please feel free to post here if anything is unclear.

Sincerely,
Walter Wang ((E-Mail Removed), remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to send a datarow item to a function? RSH Microsoft VB .NET 3 12th Oct 2007 02:27 AM
Altering value to be returned by DataRow.Item Joe Microsoft ADO .NET 4 13th Sep 2006 05:57 AM
DataRow and Item Vik Microsoft C# .NET 5 30th Jun 2006 03:59 PM
getting the datatype of a datarow item Michael Jackson Microsoft ADO .NET 1 7th Sep 2005 07:09 AM
DataRow.Item return Edward Diener Microsoft ADO .NET 13 25th Nov 2004 04:58 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:54 AM.