• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 215
  • Last Modified:

Convert a string to XML

Hi

I want to save the address in the database using XMLString.
LIKE FIRST NAME,LASTNAME,ADDRESS,CITY ETC ARE different textboxes on the aspx page.
i want to concatenate the value of all these in a xmlstring and want to save it to database like

<Address>
<Bvin /><NickName /><FirstName /><MiddleInitial /><LastName /><Company />
<Line1 /><Line2 /><Line3 /><City /><RegionName /><RegionBvin /><PostalCode />
</Address>

Using C#.

Thanks
0
ASPNET_8
Asked:
ASPNET_8
1 Solution
 
guveraCommented:
0
 
Didier VallySystems Engineer and Finance AnalystCommented:
I suggest you use the XmlTextWriter class from Microsoft :
http://msdn.microsoft.com/fr-fr/library/system.xml.xmltextwriter.aspx

0
 
Plk_In_EECommented:
Hi there,
This can be accomplished as below, sample code snippet.

DataSet reportData = new DataSet();
reportData.ReadXml(Server.MapPath(”report.xml”));

SqlConnection connection = new SqlConnection(”CONNECTION STRING”);
SqlBulkCopy sbc = new SqlBulkCopy(connection);
sbc.DestinationTableName = “report_table”;
       
//if your DB col names don’t match your XML element names 100%
//then relate the source XML elements (1st param) with the destination DB cols
sbc.ColumnMappings.Add(”campaign”, “campaign_id”);
sbc.ColumnMappings.Add(”cost”, “cost_USD”);
connection.Open();

//table 4 is the main table in this dataset
sbc.WriteToServer(reportData.Tables[4]);
connection.Close();
//remove the xml file
---
0
 
ASPNET_8Author Commented:
OK
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now