Getting a value using a column name instead of index

headkaze

Member
Joined
Sep 5, 2006
Messages
23
I am writing a simple PhoneBook database program, and part of it requires me to get the values of the currently viewed record.

I am using BindingManagerBase to handle browsing through the Phone Book.

Right now I am using the following line to get the value of column 0 ("Phone") to retrieve the phone number of the currently viewed record.

C#:
dataSet11.Tables["PhoneBook"].Rows[this.bindManager.Position].ItemArray[0]

I am wondering, can I possibly get the value like ItemArray[] but using the columns name. The above line gives me the value of "Phone". But I would like to use the columns name "Phone". Eg. ItemArray["Phone"], but obviously that only accepts a int index value. I cant seem to find a simple way to do it.
 
Just remove ".ItemArray" and you should be able to enter a string the the square brackets, i.e.,
C#:
dataSet11.Tables["PhoneBook"].Rows[this.bindManager.Position]["Phone"]
 
IUnknown said:
Just remove ".ItemArray" and you should be able to enter a string the the square brackets, i.e.,
C#:
dataSet11.Tables["PhoneBook"].Rows[this.bindManager.Position]["Phone"]

Thanks it works well :)
 
Back
Top