Dynamic columns RRS feed

  • Question


    This seems to be an issue that gets bounced around a lot, but I can't seem to find anything useful that fits my particular circumstances. I have a table with a large number of columns that is ultimately goin to be bound to a grid control that will allow the user to show and hide columns as needed.


    Is it really a bad idea to have chunks of SQL that I can piece together in response to the columns that the user selects to view in the grid? Is there a better way?



    Tuesday, September 11, 2007 4:56 AM

All replies

  • Why do you seem to have the idea that "get only what you need from the database" is a bad idea?

    The issue lies in *how* you gather the columns from the user, and how you use them to generate the query.. (Read: make sure the user can't insert anything malicious..")

    (You might want to examine if you're data has been normalized well if you have a large number of columns in your table though)
    Tuesday, September 11, 2007 5:49 AM
  • Right, ok, I guess my language was a bit general. Upon further reflection, I'm not sure why I phrased it that way. I'm just trying to see if there are any more efficient ways of doing this.


    The table is very normalized, it's just a very detailed and flexible entity. We've been over it many times, and the current structure seems to be the best. We've moved some stuff out of the table, but the user still needs access to the data so the results returned could still have as many as 40-50 columns.



    Thanks for jogging my thoughts back on track.
    Tuesday, September 11, 2007 6:19 AM