How to reference the value of a specific field in a DataSet

G

Guest

I've just filled a dataset with 1 row from a table in my database
I want to get the value of one of the fields

I'm using

string atLastMyValue
DataSet ds
DataTable dt
DataRow dr; in myTable.Rows
DataColumn dc
dt = ds.Tables[0]
dr = dt.Rows[0]
dc = dt.Columns["myFieldName"]
atLastMyValue = dr[dc].ToString()

Is there a simpler way to reference the field?
 
M

Marina

Yes: myDS.Tables["MyDataTable"].Rows[0]["MyColName"] will gives you the
value of MyColName in the first row of a datatable named MyDataTable.
 
G

Guest

Yes

atLastMyValue = ds.Tables[0].Rows[0]["myFieldName"].ToString()

----- Grant Ord wrote: ----

I've just filled a dataset with 1 row from a table in my database
I want to get the value of one of the fields

I'm using

string atLastMyValue
DataSet ds
DataTable dt
DataRow dr; in myTable.Rows
DataColumn dc
dt = ds.Tables[0]
dr = dt.Rows[0]
dc = dt.Columns["myFieldName"]
atLastMyValue = dr[dc].ToString()

Is there a simpler way to reference the field?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top