I have a table in my database called Grades which contains a set of columns (named column1, column2 and so forth) each containing different student grades (in the form of strings). In my C# application I would like to change these values through the webservice setGrade() method.
In future I will add more grade columns to the database but I do not want to have to change my code accordingly each time. I tried to write my code such that for each column that exists in the Database table Grades the value "Very good" is inserted. On debugging I am told that I can not use my string "temp" as a command on the webservice record "grade." Is there another way of doing this?
protected void Test()
for (int i = 0; i < myGrades.Length; i++)
string temp = "column" + i;
grade.temp = "Very good"; // I.e. grade.column1, grade.column2, etc.
Oh ok, thanks, I wasnt sure if it was possible to change the code like that or not
It might be possible, but that doesn't necessarily mean it's the approach you should take.
Generally in database design, you don't want to have to make schema changes (like adding a column), whenever some common event occurs (like a new academic class being put on the schedule).
The approach where you add a new column for a class works okay for a small school, but it doesn't scale. Imagine a school with 1000 classes offered - it wouldn't be practical to have a table with 1000 or more columns.