A large amount of XML comes in (about 1.5 GB), I need to transfer the information from them to the database table (in my case, SQL CE). The structure of the XML file is the following (the root tag, and there are many identical tags with attributes, the number of attributes is about 20), in essence, a two-dimensional table is

<Objects> <Object ID="" name="" level="" /> <Object ID="" name="" level="" /> 

With XML through XmlReader try this:

 XmlReader r = XmlReader.Create("file:////" + PathToFile); while (r.Read()) { if ((r.Name == "Object") && (r.HasAttributes)) { } } 

But how can I connect it further with IDataREader and SqlCeBulkCopy I can not understand

The library is here.

UPDATE

  • Give me a more detailed question for the people. What library you use, why you should use IDataReader for SqlCeBulkCopy, a link to the previous question and answer. I know something, but others do not. There you can write an example for 30 minutes. I don't have time for it now, but I can eat others. - mals

2 answers 2

You need to implement the IDataReader interface in a new class

here is a detailed implementation for the collection

 public class CustomObjectDataReader : IDataReader { ... } 

Be sure to implement these properties and methods, the rest can return an exception

  • Fieldcount
  • Getname
  • GetOrdinal
  • Getvalue
  • Read
  • I still can not understand) - e1s
  • what exactly is not clear? - Arsen Mkrtchyan
  • How to link XmlReader and IDataReader - e1s
  • In your link, they fill in the List , and it will be problematic for me to upload my XML there, because most likely there won't be enough memory. - e1s
  • List does not matter, IEnumerable can be used there, in fact, you can read xml via xmlreader, the main thing to read is the right way to implement the method - Arsen Mkrtchyan

If you need to upload the entire file, then why do you need an IDataReader?

Use just SQLXMLBULKLOADLib. An example is here .

Well, if IDataReader is desperately needed, then look here . May help ...

  • C SQL Server CE this library does not work, or do you know how to make them friends? I would be very grateful - e1s