c# - Save XML data to SQL Server table -
i have xml file, , want save value number
(for example) sql server table.
<order> <order_header> <number>10945</number> <time>7.8.2013 12:45:20</time> <note>this note</note> </order_header> </order>
this code:
xdocument doc = xdocument.load("c:\\users\\l\\desktop\\data.xml"); var number = doc.descendants("number"); var time = doc.descendants("time"); var note = doc.descendants("note"); foreach (var cislo in number) { sqlconnection conn = new sqlconnection("data source=***"); conn.open(); using (sqlcommand cmd = conn.createcommand()) { cmd.commandtext = "update cislo set cislo = @cislo1;"; cmd.parameters.addwithvalue("@cislo1", doc); cmd.executenonquery(); } } messagebox.show("ok");
i error:
there no mapping object type system.xml.linq.xdocument known managed provider native type.
on row:
cmd.executenonquery();
you passing 'doc', xdocument, parameter. try changing
cmd.parameters.addwithvalue("@cislo1", doc);
to
cmd.parameters.addwithvalue("@cislo1", cislo);
Comments
Post a Comment