hyd
hyd1
i want to store the above xml data in backend(sqlserver2008) by automatically create new table
like table as folllows
name address
x hyd
y hyd1
plz help me.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Naresh Babu GopavaramPosted Mar 30, 2011, 11:31 PM
Micke BlomqvistPosted Mar 28, 2011, 6:26 AM
Micke BlomqvistPosted Mar 25, 2011, 8:34 AM
Please note the comments regarding dynamic datatypes, you need to finetune this your self. Let me explain the code a bit:
1. I copied your xml data and fixed the bad formatting. ( wasn't closed correctly)
2. Read data using DataSet ReadXml method.
3. I use a HashTable to loop thru the columns in the datatable to create a base for keeping track of the max length of the fields.
4. Set the MaxLenght using the stored values in the HashTable. (This is a must to create a varchar column in SQL Server)
5. Loop thru the column once again to create the "CREATE TABLE" statement.
5. SELECT CASE from the information_schema.tables table to check whether the table exists or not
6. If the table doesn't exists, use the CREATE TABLE statement to create the table
7. If there are rows in the table, use SqlBulkInsert to load the data from the DataTable to the SQL Server table.
8. All set!
Please let me know if you have any problems!