I’m coding in c# on webpages/razor with MS SQL database
I have a table with the following columns
- Sat1
- Sat2
- Sat3
- Sat4
- …
- Sat25
I want to loop through each of these, and assign the value to satAvail
I have the following
for (var i = 1; i < 26; i++)
{
satWeek = "Sat" + i;
satAvail = item.satWeek;
}
I want the equivalent of satAvail = item.Sat1;
I’ve tried a few different lines but having no joy
I’m not sure I’m clear on your actual requirement, but in general, when working with the Database helper, if you want to access a column value resulting from a
Database.QueryorDatabase.QuerySinglecall, you can either do it using dot notation or an indexer.For example, you may get data doing this:
If you know want to access the value of a column called
Sat1, you would useitem.Sat1. However, if the column name is represented as a variable, you would need to use an indexer instead: