Frapie
Frapie

Reputation: 225

How do I extract specific data from a datatable?

I am creating a game where all my enemies are located in a database. I put the table in my datatable, but how do I access specific data in it? For example, I want to access the enemy that is an elf in the datatable. I know you can use foreach to display the entire row, but I want to only get certain values from that row to create my enemy object.

Upvotes: 0

Views: 3081

Answers (1)

Mike Perrenoud
Mike Perrenoud

Reputation: 67898

To access specific data in a DataTable you can do it like this:

dataTable.Rows[0][0]

or you can do it by field name:

dataTable.Rows[0]["field_name"]

and so then you can initialize your properties with statements like that.


If you're working with a DataRow[] like @lazyberezovsky is saying then it might look something like this:

dataRowArray[0][0]

or:

dataRowArray[0]["field_name"]

Upvotes: 1

Related Questions