Click here to Skip to main content
15,795,942 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am working on a desktop application.

So there are different buttons on the front end and a click on that button fetch the information from hardware connected to PC via Serial Port and store that data into database and shows the information.

Problem is that if i create a table in my database with 18 columns and suppose the information fetch requires 19 columns then i will have to add 1 column at run time.

same if less no of columns are required.

What I have tried:

1.I read about EAV but I didn't understand it.

2.I was thinking about taking maximum numbers of columns required and just showing or not showing them at the front end.
Updated 30-Jul-23 1:11am

1 solution

You can add columns, but it's complicated - not in the actual code, it's an SQL ALTER TABLE command: SQL ALTER TABLE Statement[^] - the problem is with existing data in the table.
If you have 18 columns, and you add a 19th, what value should go into that column for existing rows? You could give the new table the NULL attribute, in which case existing rows will get NULL values, but if you do that you will still have to deal with those nulls in your presentation software later. And ... if your table has a significant number of rows this could be extremely inefficient, as SQL has to create a whole new table and copy existing data into it before removing the old table.

My personal feeling is that you are doing something wrong: I'd be included to ask myself "why is this device giving me a different number of rows?", "when the row count changes, does the row order?", "will this mean that existing data is no longer in the right column?", and "what happens if the device decides to send me less columns?"
All of these could have profound results on your code reliability and data integrity later - and once you get data integrity problems, they are a nightmare to fix!
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900