Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
we get XML/XSD files from third party.
Based on the files we need to create tables in the database using C#.NET.
Could you help with this.

Thanks
Posted
Comments
[no name] 28-Jun-14 16:10pm    
You have not said what you need help with.
George Jonsson 28-Jun-14 23:53pm    
Do you need to create the tables from using XSD as a template or do you need to fill the tables with data from an XML file?
Sitaramaiah E 29-Jun-14 9:40am    
Hi George,
I need to create the tables using XSD as template.
George Jonsson 29-Jun-14 11:13am    
Well, that is kind of a tall order.
1. Parsing an XSD file is not exactly trivial.
XSLT is probably the best option.

2. How do you want to create the tables?
2.1 Via direct SQL from c# code?
If so the SQL flavor has to be known. (Oracle, MS SQL, MySQL)
2.2 Via a Stored Procedure?
This is the more generic approach.

3. How to treat tables in XSD without primary keys?
Assume that you add an auto-incremental ID as the primary key?

And probably some more questions I haven't considered yet.
// George

1 solution

Hi,

First make datatable from xml like this:

C#
DataTable table;

       private void createDatatableFromXML()
       {
           table = new DataTable();
           string dataFile = @"DatafileLocation\datafile.xml";
           if (File.Exists(dataFile))
           {
               table.ReadXml(dataFile);

           }
           else
           {
              //Do som messaging
               return;
           }
       }


If You want to create a sql database from the dataTable see this:http://stackoverflow.com/questions/1348712/creating-a-sql-server-table-from-a-c-sharp-datatable[^]

Hope this can help You,

Groover
 
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