No Item in C# ?

  • Thread starter Thread starter Stijn Verrept
  • Start date Start date
S

Stijn Verrept

I found several code examples on the net but this doesn't want to work.

Label2.Text = filesIDData1.Tables["Files"].Rows[2].Item["TP_Name"];

There isn't a Item property in C# while all the examples have one. How
should I do this? I need the value of the field TP_Name of the
selected row (just put 2 there for now) .

I found another msg on usegroups with the same question but no answer.
 
Stijn,

I don't know if this will work but in vb.net the syntax can use item or omit
item like this:

Label2.Text = filesIDData1.Tables("Files").Rows(2)("TP_Name")

You could see if the same works in c# (I haven't tested it myself):

Label2.Text = filesIDData1.Tables["Files"].Rows[2]["TP_Name"];

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
 
Hello Stijn,

Stijn Verrept said:
I found several code examples on the net but this doesn't want to work.

Label2.Text = filesIDData1.Tables["Files"].Rows[2].Item["TP_Name"];
try
Label2.Text = filesIDData1.Tables["Files"].Rows[2]["TP_Name"];
 
Simon said:
Hello Stijn,

Stijn Verrept said:
I found several code examples on the net but this doesn't want to
work.

Label2.Text = filesIDData1.Tables["Files"].Rows[2].Item["TP_Name"];
try
Label2.Text = filesIDData1.Tables["Files"].Rows[2]["TP_Name"];

Works great thanks!
 
Stijn Verrept said:
I found several code examples on the net but this doesn't want to work.

Label2.Text = filesIDData1.Tables["Files"].Rows[2].Item["TP_Name"];

There isn't a Item property in C# while all the examples have one. How
should I do this? I need the value of the field TP_Name of the
selected row (just put 2 there for now) .

I found another msg on usegroups with the same question but no answer.

As an explanation of the other answers: if you look at the MSDN docs for the
Item method, then you see a line "In C#, this property is the indexer for
the <classname> class."
For languages that do not support the indexer syntax, you can use the Item
method.
C# does support indexers, so you can ignore "Item" and just use [].

Hans Kesting
 
Back
Top