Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 SSIS and Import/Export (2005)
 How to save Dynamic Grid values in Table

Author  Topic 

Kalaiselvan
Posting Yak Master

112 Posts

Posted - 2012-03-13 : 03:59:13
Hi,
Need some suggestions to save the Grid data in table. Were as the Grids columns will be dynamic.

Grid View:
[ID] [COL1] [COL2] [COL3] ... [COLn] [AMT]
1 100 100 100 100 10000
2 50 100 75 50 7500
3 200 250 25 150 15000
4 300 100 100 100 65000
5 150 75 100 200 50000

From the above grid, need to save it in table. If its taken in XML am unable to retrieve the datas as table in SQL server. Please suggest me how to retrieve the datas from Grid to SQL and how to save it in table. Since all the datas are Dynamic unable to capture it in tables.

Regards,
Kalai

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-03-13 : 07:13:47
By "Grid data", I assume you mean that the data to be saved is in a front-end application in something like a Datagrid object. If that is the case, and if the columns are truly dynamic this would be one of those rare cases where you do want to store the data as XML.

Depending on your requirements, you can stored the data in a table with two columns - an ID column to store the ID and an XML column to store the row. Alternatively, you might simply XMLSerialize all the data in the grid and store it.

If you don't want to use XML and do want to store it in a relational table, you will need a table which has all possible columns. Then, you would need to examine each column header and store the data in the table that maps to that column header. It is a lot more work, and also would break if your grid were to end up with brand new columns that you had not initially considered.

There are other alternatives, each with its own baggage - for example, you could store the data in sql_variant columns, you could store them as entity-attribute-values (don't do that!) etc.

Apart from all the questions about how to store the data, it is hard for me to visualize a business scenario where you have random, out of the blue datagrids with columns that you have no idea about. Is that really truly the case, or can the business problem be broken down into more well-defined smaller chunks?
Go to Top of Page
   

- Advertisement -