Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using DataSet object

Status
Not open for further replies.

stuartd

Programmer
Jan 8, 2001
146
US
Hi

I am using the SqlCommand/DataAdapter/DataSet to read some records from a table. I then put the results into some text boxes. I am using Rows, and ItemArray :

Code:
				txtEventID.Text=oDS.Tables["Events"].Rows[x].ItemArray[0].ToString();
				txtEventName.Text=oDS.Tables["Events"].Rows[x].ItemArray[4].ToString();
				txtCode.Text=oDS.Tables["Events"].Rows[x].ItemArray[5].ToString();
But is there a way of accessing the DataSet by the table field names ? Like:

Code:
				txtEventID.Text=oDS.Tables["Events"].Rows[x].[b]ItemArray["ID"][/b].ToString();
				txtEventName.Text=oDS.Tables["Events"].Rows[x].[b]ItemArray["Name"][/b].ToString();
				txtCode.Text=oDS.Tables["Events"].Rows[x].[b]ItemArray["Code"][/b].ToString();
Obviously this does not work, but is there a way to do it like this?

SD
 
Stuart,

Is there a specific reason why you need to use it as an item array?? If not, you could just list the column in square braces after the row:

Code:
DataSet ds = new DataSet();
ds.Tables[1].Rows[1]["SomeColumn"].ToString(); //By column Name
ds.Tables[1].Rows[1][1].ToString(); //By column index

Good luck,
Kevin

- "The truth hurts, maybe not as much as jumping on a bicycle with no seat, but it hurts.
 
No reason (other than not knowing how to do it correctly in the first place).

SD
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top