how to Save Matrix
-
Imagine a matrix,
S M L XL color1 10 20 30 0 color2 4 5 45 50 color3 1 0 4 5
You a sample matrix what i work on. columns are quantity of sizes (some of them may equals to 0 ) . Rows are colors. rows count and columns count are variable. How to save them to data base. rows are in a table, size are saved on other table. But i couldnt solve how to save values on table. what do you offer to me ? -
Imagine a matrix,
S M L XL color1 10 20 30 0 color2 4 5 45 50 color3 1 0 4 5
You a sample matrix what i work on. columns are quantity of sizes (some of them may equals to 0 ) . Rows are colors. rows count and columns count are variable. How to save them to data base. rows are in a table, size are saved on other table. But i couldnt solve how to save values on table. what do you offer to me ?Store the sizes in one table, the model in one table, and the quantities in one table. Size (SizeId int, SizeName varchar) 1, 'S' 2, 'M' 3, 'L' 4, 'XL' Model (ModelId int, ModelName varchar) 1, 'color1' 2, 'color2' 3, 'color3' ModelQuantity (ModelId int, SizeId int, Quantity int) 1, 1, 10 1, 2, 20 1, 3, 30 1, 4, 0 2, 1, 4 2, 2, 5 2, 3, 45 2, 4, 50 3, 1, 1 3, 2, 0 3, 3, 4 3, 4, 5 Alternatively, you can choose to not store any record for the quantities that are zero. --- b { font-weight: normal; }
-
Store the sizes in one table, the model in one table, and the quantities in one table. Size (SizeId int, SizeName varchar) 1, 'S' 2, 'M' 3, 'L' 4, 'XL' Model (ModelId int, ModelName varchar) 1, 'color1' 2, 'color2' 3, 'color3' ModelQuantity (ModelId int, SizeId int, Quantity int) 1, 1, 10 1, 2, 20 1, 3, 30 1, 4, 0 2, 1, 4 2, 2, 5 2, 3, 45 2, 4, 50 3, 1, 1 3, 2, 0 3, 3, 4 3, 4, 5 Alternatively, you can choose to not store any record for the quantities that are zero. --- b { font-weight: normal; }
i already did so , but i think it is not effective way. When reports i show these values as a table (using listview object). But it is hard to populate values in to a listview. First i read just columns for creating column header Then i try to read values at ModelQuantity for rows. Care that all color1 values must be at the same row. So after for datareader.read process , i create a listviewitem object.
-
i already did so , but i think it is not effective way. When reports i show these values as a table (using listview object). But it is hard to populate values in to a listview. First i read just columns for creating column header Then i try to read values at ModelQuantity for rows. Care that all color1 values must be at the same row. So after for datareader.read process , i create a listviewitem object.
It's the best way if you consider possible changes in the future. You can for an example add the size "XXL" without having to change the data model. If you give up that flexibility, you could store all sizes for a model in a single record, with each quantity in a field. This would make it simpler to get the data, but if you need to add a size it requires changes in the database and in the code. --- b { font-weight: normal; }
-
It's the best way if you consider possible changes in the future. You can for an example add the size "XXL" without having to change the data model. If you give up that flexibility, you could store all sizes for a model in a single record, with each quantity in a field. This would make it simpler to get the data, but if you need to add a size it requires changes in the database and in the code. --- b { font-weight: normal; }