Hey, I'm pulling data from a table, and storing it into a DataRow. Per MSDN , I should be able to get an item from the row simply by dRow.Item("time"), but I only get the option of using ItemsArray. Is there any specific reason this would happen? Thanks. Link to picture showing the intellisense (correct name?) picture here

Relevant code:

    DataSet dataStore = new DataSet();
    SqlDataAdapter runDataAdapter = new SqlDataAdapter("SELECT * From runsTable", sqlConnection);
    runDataAdapter.Fill(dataStore, "Runs");
    DataRow dRow = dataStore.Tables["Runs"].Rows[0];

Edited by dare599z

6 Years
Discussion Span
Last Post by dare599z

You should be able to access you item by using
string t = dRow["time"].ToString();

Votes + Comments
Fast, concise, it worked.

That works! Thank you very much for the fast response! Is that what the "Extension Methods" section in on the MSDN link? (For future reference)


Yes, that is using one of the extension methods as described in MSDN. You could also access a column in your DataRow by index, i.e. assuming "time" is the first column in the DataRow, you could get its value with:
`string t = dRow[0].ToString();
Anyway, using the name of the column is probably better for code readability reasons and also it won't fail in case you decided to change the order of the columns in your SQL query.


I appreciate the input. It's similar to the way that I was using before you told me how to do this, in the picture I posted. I was following a tutorial online and it says to use it by index, but I didn't really like that, and would rather do it by string. Thank you again.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.