I understand this method of getting DB data (using foreach):

  var db = Database.Open("Connection");
  var rows = db.Query("SELECT 1 columnName,2 columnName2 FROM Table");

  foreach(var row in rows){
      var data = row.columnName;
      var data = row[0];          

This works, but how do I get the data without using a foreach?

  var data = rows[0][1];

^ This doesn't work.

Basically, I am trying to figure out how to get the data without using a foreach. What would I have to do?


.Query() returns:

Type: System.Collections.Generic.IEnumerable

The rows returned by the SQL query.

As shown here: http://msdn.microsoft.com/en-us/library/webmatrix.data.database.query%28v=vs.111%29.aspx

Related posts

Recent Viewed