It's a rather straight forward procedure to come up with a solution (I'll assume that the tables are already created in your DB):
- Extract the table name and column name(s), value(s) and type(s) from your XML. One way to achieve that would be the use of XPath expressions.
- Construct insert statements from the data retrieved in step 1.:
String myStringSQLStatement = String.Format("INSERT INTO {0} {1} VALUES({3})", tableName, columnList, paramNameList);
where tableName
is the table name from the XML and the columnList
is the list of the column names seperated by a comma. For the paramNameList
use the column names prefixed by a @ and also separate them by a comma. - Next make a connection to your DB, create a SQL statement form the string you generated.
- Next add SqlParameters to you statement with the appropriate type which you also fetched from your XML.
- Run your SqlStatement and fetch the results.
Follow this route, keep your question updated with your progress and tell us if you run across any problems while you're working this out.
Best Regards,
--MRB