Right now, I'm using a MySqlDataReader
to read the result from a query and using reader.GetInt()
, reader.GetString()
, etc. to get the value of each cell like so:
var cmd = new MySqlCommand(query, conn);
var reader = cmd.ExecuteReader();
while(reader.Read()) {
myfirstvalue = reader.GetInt32(0);
mysecondvalue = reader.GetString(1);
mythirdvalue = reader.GetString(2);
...
}
This works and all, but it kind of grabs the values blindly. You might get an unexpected value if the order of the results gets changed.
Can I retrieve the returned results by column name? Back in my PHP days, you could get an array and access the values like $results['mycolumn']
. Is this possible in C#?