473,326 Members | 2,192 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

DataRow.Item

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
Aug 29 '06 #1
2 3034
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" <Ga******@newsgroups.nospamwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
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


Aug 29 '06 #2
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 (wa****@online.microsoft.com, 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.

Aug 29 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: dudi | last post by:
I am encountering the following strange problem which causes the application to use more memory then it should. I have 5 database tables. lets pretend I want to load each one of them into a...
3
by: Phil | last post by:
Hi, I have a client/server app. that uses a windows service for the server and asp.net web pages for the client side. My server class has 3 methods that Fill, Add a new record and Update a record....
3
by: Shravan | last post by:
Hi, How can I bind DataRow array to ComboBox. I tried setting DataSource -> DataRow Array DisplayMember -> ColumnName But it was showing "System.Data.DataRow" for every item in the...
4
by: Marc van den Bogaard | last post by:
hello together, my datarow.item property is missing, i just can accesss the ItemArray property, what is wrong with this? System.Data.DataSet dataset1 = new System.Data.DataSet(); ...
4
by: Michael Carr | last post by:
I have a function that populates a class with values from a database. I'd like to pass into the function either a SqlDataReader or a DataRow, depending on which mechanism I'm using to retrieve data...
3
by: News | last post by:
Hi, I wrote a function that pulls a record, below: ++++++++++++++++++++++++++++++++++++++++ Public Function getServPlanProgActivity( serviceprogramenroll_id As Integer, activity_id As Integer )...
2
by: Ali M | last post by:
Hi, I am creating a TextBox dynamically at runtime within a Panel, and I want to bind its Text property to a DataColumn in a DataRow. What is the correct method for doing this... The following...
11
by: Tim Frawley | last post by:
I need to return a DataRow or the Row Index in a DataSet wherein the value I am attempting to find is not a primary key. I have to do this often, more than 200 times when importing a file so it...
3
by: RSH | last post by:
Hi, I have a situation where I need to send a Datarow.tiem to a function for processing. I cant figure out the right type to specify in the function to receive the item. What should it be? ...
9
by: myotheraccount | last post by:
Hello, Is there a way to convert a DataRow to a StringArray, without looping through all of the items of the DataRow? Basically, I'm trying to get the results of a query and put them into a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.