-
February 4th, 2010, 12:46 PM
#1
[RESOLVED] Use a string as a command?
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?
Code:
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.
WebServiceConnection.webService.setGrade(grade);
}
}
-
February 4th, 2010, 12:53 PM
#2
Re: Use a string as a command?
Can we see the setGrade(...) method?
-
February 4th, 2010, 02:08 PM
#3
Re: Use a string as a command?
Sounds like you need to change the design of your database to make it more scalable (and give you the abilitity to add grades for new classes without further db or code changes).
-
February 5th, 2010, 03:29 AM
#4
Re: Use a string as a command?
Oh ok, thanks, I wasnt sure if it was possible to change the code like that or not
-
February 5th, 2010, 09:39 AM
#5
Re: Use a string as a command?
Originally Posted by stephsh
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.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|