S
S
stilet492018-06-01 14:34:36
C++ / C#
stilet49, 2018-06-01 14:34:36

How to refer to a child XML element?

There is an XML document of the following form
4oWq1MDOQ44.jpg
. There is also a code with which records from XML are written to a table in MS SQL

XDocument Doc =  XDocument.Load(DocFile);
                using (SqlCommand cmd = conn.CreateCommand())
                { cmd.CommandText = "DELETE FROM [dbo].[Rab]";
                  cmd.ExecuteNonQuery();
                }
                    var zl = Doc.Descendants("zl").Select(x => new { NOMER_Z = (int?)x.Element("nomer_z"), ID_ZL = (int)x.Element("id_zl"), FAM = (string)x.Element("fam"),
                        IM = (string)x.Element("im"), OT = (string)x.Element("ot"), DOSTDR = (int?)x.Element("dostdr"), DR = (string)x.Element("dr"), W = (string)x.Element("w"),
                        NAME_DOC = (int?)(x.Element("doc").Element("name_doc")), S_DOC = (string)x.Element("s_doc"), N_DOC = (string)x.Element("ndoc") }).ToList();
                progressBar1.Maximum = zl.Count;
                foreach (var item in zl)
                {
                    using (SqlCommand cmd = conn.CreateCommand())
                    {
                        cmd.CommandText = "Insert INTO Rab (NOMER_Z,ID_ZL,FAM,IM,OT,DOSTDR,DR,W,NAME_DOC,S_DOC,N_DOC) VALUES (@nomer_z,@id_zl,@fam,@im,@ot,@dostdr,@dr,@w,@name_doc,@s_doc,@n_doc);";
                        cmd.Parameters.AddWithValue("@nomer_z", item.NOMER_Z);
                        cmd.Parameters.AddWithValue("@id_zl", item.ID_ZL);
                        cmd.Parameters.AddWithValue("@fam", item.FAM);
                        cmd.Parameters.AddWithValue("@im", item.IM);
                        cmd.Parameters.AddWithValue("@ot", item.OT);
                        cmd.Parameters.AddWithValue("@dostdr", item.DOSTDR);
                        cmd.Parameters.AddWithValue("@dr", item.DR);
                        cmd.Parameters.AddWithValue("@w", item.W);
                        cmd.Parameters.AddWithValue("@name_doc", item.NAME_DOC);
                        cmd.Parameters.AddWithValue("@s_doc", item.S_DOC);
                        cmd.Parameters.AddWithValue("@n_doc", item.N_DOC);
                        cmd.ExecuteNonQuery();

                        //cmd.Clone();
                    }

How to take values ​​from rows highlighted in yellow?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Farwisdomer, 2018-06-01
@Farwisdomer

https://metanit.com/sharp/tutorial/16.4.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question