CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2010
    Posts
    130

    [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);
                }
            }

  2. #2
    Join Date
    Apr 2007
    Location
    Florida
    Posts
    403

    Re: Use a string as a command?

    Can we see the setGrade(...) method?

  3. #3
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    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).

  4. #4
    Join Date
    Jan 2010
    Posts
    130

    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

  5. #5
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Use a string as a command?

    Quote Originally Posted by stephsh View Post
    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
  •  





Click Here to Expand Forum to Full Width

Featured