locked
loading gridview from sql with mapping RRS feed

  • Question

  • User-1767698477 posted

    I have in my sql database what are multiple rows of the gridview on 1 row in the sql table.  There are about 20 columns per row. Item1this, item2 that, item1somethingelse....item1lastitem, then it's item2this, item2that.....

    This is all on 1 row in the sql table.  Is this bad practice?  Let's say it's ok but how do I tell the gridview that a NEW ROW starts after you arrive at item2this ?

    My concern was about the table getting too big. My thinking was that putting 10 of the items on one line in the table would save space. I have a table adapter which loads the data. Would it be possible to do a for each on the tableadapter, and after getting to item 20 start a new row? If so, how would this loop work?

    Sunday, May 2, 2021 7:30 PM

Answers

  • User409696431 posted

    Yes, it is bad design. Put each row of data in a different row in the database table.  To use your current design, you'd have to fetch the data into a DataTable in code behind, write code to parse each line of that table and create a new DataTable by adding a new row for each item it finds in each line, then bind the GridView to that new DataTable.  In short, you'd have to undo what you did when creating your current table.

    Databases are designed to be quite efficient with tables with many rows.  You may be trying to solve a problem you don't have.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 3, 2021 3:26 AM

All replies

  • User475983607 posted

    I don't understand your design.  Why does one row contain multiple records?  Why not simply follow standards where each row is a record?

    Sunday, May 2, 2021 10:52 PM
  • User409696431 posted

    Yes, it is bad design. Put each row of data in a different row in the database table.  To use your current design, you'd have to fetch the data into a DataTable in code behind, write code to parse each line of that table and create a new DataTable by adding a new row for each item it finds in each line, then bind the GridView to that new DataTable.  In short, you'd have to undo what you did when creating your current table.

    Databases are designed to be quite efficient with tables with many rows.  You may be trying to solve a problem you don't have.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 3, 2021 3:26 AM
  • User-1767698477 posted

    Thanks, I have changed my design to put one record on each row.

    Tuesday, May 11, 2021 3:01 AM