Advertisement
Guest User

adadadad

a guest
Feb 24th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.05 KB | None | 0 0
  1. //11111111111111111111111111111111111111111
  2. /*using System;
  3. using System.Xml;
  4. namespace ReadingXML2
  5. {
  6. class Class1
  7. {
  8. static void Main(string[] args)
  9. {
  10. // Create a new file in C:\\ dir
  11. XmlTextWriter textWriter = new
  12. XmlTextWriter("C:\\Users\\Yan\\Desktop\\BiBD-6lab\\BIBD\\BIBD4\\1.xml", null);
  13. // Opens the document
  14. textWriter.WriteStartDocument();
  15. // Write comments
  16. textWriter.WriteComment("First Comment XmlTextWriter Sample Example");
  17. // Write first element
  18. textWriter.WriteStartElement("Student");
  19. textWriter.WriteStartElement("r", "RECORD", "urn:record");
  20. // Write next element
  21. textWriter.WriteStartElement("Name", "");
  22. textWriter.WriteString("Student");
  23. textWriter.WriteEndElement();
  24. // Write one more element
  25. textWriter.WriteStartElement("Address", "");
  26. textWriter.WriteString("Colony");
  27. textWriter.WriteEndElement();
  28. // WriteChars
  29. char[] ch = new char[3];
  30. ch[0] = 'a';
  31. ch[1] = 'r';
  32. ch[2] = 'c';
  33. textWriter.WriteStartElement("Char");
  34. textWriter.WriteChars(ch, 0, ch.Length);
  35. textWriter.WriteEndElement();
  36. // Ends the document.
  37. textWriter.WriteEndDocument();
  38. // close writer
  39. textWriter.Close();
  40. }
  41. }
  42. }*/
  43. //22222222222222222222222222222222222222222
  44. /*
  45. using System.Data;
  46. using System.Data.OleDb;
  47. using System.Drawing;
  48. using System.Linq;
  49. using System.Text;
  50. using System.Xml.Linq;
  51. using System.Xml;
  52. using System.IO;
  53.  
  54. using System;
  55. using System.Xml.XPath;
  56.  
  57. class XMLtoACCESS
  58. {
  59. static void Main(string[] args)
  60. {
  61. XDocument myXML = XDocument.Load("C:\\Users\\Yan\\Desktop\\BiBD-6lab\\BIBD\\BIBD4\\Product.xml");
  62. foreach (XElement el in myXML.Root.Elements("Product"))
  63. {
  64. if (el.Element("id").Value == "1")
  65. {
  66. Console.WriteLine(el);
  67. }
  68. }
  69. Console.ReadKey();
  70. }
  71. }*/
  72. //33333333333333333333333333333333333333333
  73. /*
  74. using System;
  75. using System.Collections.Generic;
  76. using System.ComponentModel;
  77. using System.Data;
  78. using System.Data.OleDb;
  79. using System.Drawing;
  80. using System.Linq;
  81. using System.Text;
  82. using System.Windows.Forms;
  83. using System.Xml.Linq;
  84. using System.Xml;
  85. using System.IO;
  86. using System.Threading;
  87.  
  88. namespace XMLApplication1
  89. {
  90. class XMLtoACCESS
  91. {
  92.  
  93.  
  94. static void Main(string[] args)
  95. {
  96. System.Diagnostics.Process.Start("IExplore.exe", "file:///C:/Users/Yan/Desktop/BiBD-6lab/BIBD/BIBD4/Product.xml");
  97. Thread ThA = new Thread(
  98. () => {
  99. var f = new Form();
  100. var b = new WebBrowser() { Parent = f, Dock = DockStyle.Fill };
  101. b.Navigate(@"C:\Users\Yan\Desktop\BiBD-6lab\BIBD\BIBD4\Product.xml");
  102. f.ShowDialog();
  103. Application.Run();
  104. }
  105. );
  106. ThA.SetApartmentState(ApartmentState.STA);
  107. ThA.Start();
  108. // ждем завершения потока
  109. ThA.Join();
  110.  
  111.  
  112. }
  113.  
  114. }
  115. }
  116. */
  117. //44444444444444444444444444444444444444444
  118. /*
  119. using System;
  120. using System.Collections.Generic;
  121. using System.ComponentModel;
  122. using System.Data;
  123. using System.Data.OleDb;
  124. using System.Drawing;
  125. using System.Linq;
  126. using System.Text;
  127. using System.Windows.Forms;
  128. using System.Xml.Linq;
  129. using System.Xml;
  130. using System.IO;
  131. using System.Threading;
  132.  
  133. namespace XMLApplication1
  134. {
  135. class XMLtoACCESS
  136. {
  137.  
  138.  
  139. static void Main(string[] args)
  140. {
  141. XDocument xDoc = XDocument.Load("C:\\Users\\Yan\\Desktop\\BiBD-6lab\\BIBD\\BIBD4\\Product.xml");
  142. XNode xNewNode = new XElement("ProductAAA", new XElement("id", "7"),
  143. new XElement("name", "Утюг"),
  144. new XElement("price", "100"),
  145. new XElement("count", "25"));
  146. xDoc.Root.Add(xNewNode);
  147. xDoc.Save("C:\\Users\\Yan\\Desktop\\BiBD-6lab\\BIBD\\BIBD4\\Product.xml");
  148. }
  149.  
  150. }
  151. }
  152. */
  153. //55555555555555555555555555555555555555555
  154. /*using System;
  155. using System.Collections.Generic;
  156. using System.ComponentModel;
  157. using System.Data;
  158. using System.Data.OleDb;
  159. using System.Drawing;
  160. using System.Linq;
  161. using System.Text;
  162. using System.Windows.Forms;
  163. using System.Xml.Linq;
  164. using System.Xml;
  165. using System.IO;
  166. using System.Threading;
  167. */
  168. //Добавление атрибута
  169. /*class Program
  170. {
  171. static void Main(string[] args)
  172. {
  173. XmlDocument xmlDoc = new XmlDocument();
  174. xmlDoc.Load(@"C:\Users\Yan\Desktop\BiBD-6lab\BIBD\BIBD4\Product.xml");
  175. XmlElement elmGarage = xmlDoc.CreateElement("Product1");
  176. elmGarage.SetAttribute("id", "9");
  177. elmGarage.SetAttribute("name", "Пылесос");
  178. elmGarage.SetAttribute("price", "350");
  179. elmGarage.SetAttribute("count", "5");
  180. xmlDoc.DocumentElement.AppendChild(elmGarage);
  181. xmlDoc.Save(@"C:\Users\Yan\Desktop\BiBD-6lab\BIBD\BIBD4\Product.xml");
  182. }
  183. }*/
  184. //замена атрибута
  185. /*class Program
  186. {
  187. static void Main(string[] args)
  188. {
  189. XmlDocument xmlDoc = new XmlDocument();
  190. xmlDoc.Load(@"C:\Users\Yan\Desktop\BiBD-6lab\BIBD\BIBD4\Product.xml");
  191. //Получаем все атрибуты элемента garage
  192. XmlAttributeCollection atrCol;
  193. atrCol = xmlDoc.DocumentElement["Product1"].Attributes;
  194. //изменяем значение атрибута id
  195. atrCol.GetNamedItem("id").InnerText = "15";
  196. xmlDoc.Save(@"C:\Users\Yan\Desktop\BiBD-6lab\BIBD\BIBD4\Product.xml");
  197. }
  198. }*/
  199. //добавление нового атрибута
  200. /*class Program
  201. {
  202. static void Main(string[] args)
  203. {
  204. XmlDocument xmlDoc = new XmlDocument();
  205. xmlDoc.Load(@"C:\Users\Yan\Desktop\BiBD-6lab\BIBD\BIBD4\Product.xml");
  206. //Получаем все атрибуты элемента garage
  207. XmlAttributeCollection atrCol = xmlDoc.
  208. DocumentElement["Product1"].Attributes;
  209. //Создаем новый атрибут
  210. XmlAttribute atrDate = xmlDoc.CreateAttribute("date");
  211. atrDate.Value = DateTime.Now.ToShortDateString();
  212. //Добавим в коллекцию новый атрибут
  213. atrCol.Append(atrDate);
  214. //Уберите комментарий возле нужного метода.
  215. //Вставить атрибут date после атрибута id
  216. atrCol.InsertBefore(atrCol["id"], atrDate);
  217. //Вставить атрибут date перед атрибутом id
  218. //atrCol.InsertAfter(atrCol["id"], atrDate);
  219. xmlDoc.Save(@"C:\Users\Yan\Desktop\BiBD-6lab\BIBD\BIBD4\Product.xml");
  220. }
  221. }*/
  222. //удаление атрибута
  223. /*
  224. class Program
  225. {
  226. static void Main(string[] args)
  227. {
  228. XmlDocument xmlDoc = new XmlDocument();
  229. xmlDoc.Load(@"C:\Users\Yan\Desktop\BiBD-6lab\BIBD\BIBD4\Product.xml");
  230. //Получаем все атрибуты элемента garage
  231. XmlAttributeCollection atrCol = xmlDoc.
  232. DocumentElement["Product1"].Attributes;
  233. atrCol.RemoveAt(4);
  234. xmlDoc.Save(@"C:\Users\Yan\Desktop\BiBD-6lab\BIBD\BIBD4\Product.xml");
  235. }
  236. }*/
  237. //66666666666666666666666666666666666666666
  238. /*using System.Data;
  239. using System.Data.OleDb;
  240. using System.Drawing;
  241. using System.Linq;
  242. using System.Text;
  243. using System.Xml.Linq;
  244. using System.Xml;
  245. using System.IO;
  246.  
  247.  
  248. class XMLtoACCESS {
  249. static void Main(string[] args) {
  250. OleDbConnection con = new OleDbConnection();
  251. con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\\Users\\Yan\\Desktop\\BiBD-6lab\\BIBD\\BIBD4\\1.mdb";
  252. OleDbDataAdapter sda = new OleDbDataAdapter();
  253. DataSet ds = new DataSet();
  254. XmlReader xmlr = XmlReader.Create("C:\\Users\\Yan\\Desktop\\BiBD-6lab\\BIBD\\BIBD4\\1.xml", new XmlReaderSettings());
  255. ds.ReadXml(xmlr);
  256. int n = ds.Tables[0].Columns.Count;
  257. con.Open();
  258.  
  259. StringBuilder query = new StringBuilder();
  260. query.Append("CREATE TABLE ");
  261. query.Append(ds.Tables[0].TableName);
  262. query.Append(" ( ");
  263. for (int i = 0; i<n; i++)
  264. {
  265.  
  266. query.Append("[");
  267. query.Append(ds.Tables[0].Columns[i].ColumnName);
  268. query.Append("] ");
  269.  
  270. query.Append("varchar(30)");
  271. query.Append(", ");
  272.  
  273. }
  274. query.Length -= 2;
  275. query.Append(");");
  276. OleDbCommand sqlQuery = new OleDbCommand(query.ToString(), con);
  277. sqlQuery.ExecuteNonQuery();
  278. for (int i = 0; i<ds.Tables[0].Rows.Count ; i++)
  279. {
  280. StringBuilder sql = new StringBuilder();
  281. sql.Append("INSERT INTO ");
  282. sql.Append(ds.Tables[0].TableName);
  283. sql.Append(" ");
  284. sql.Append("( ");
  285.  
  286. for (int k = 0; k<n; k++)
  287. {
  288.  
  289. sql.Append("[");
  290. sql.Append(ds.Tables[0].Columns[k].ColumnName);
  291. sql.Append("] ");
  292. sql.Append(", ");
  293.  
  294. }
  295. sql.Length -= 2;
  296. sql.Append(")");
  297. sql.Append(" values ( ");
  298.  
  299. for (int j = 0; j<n; j++)
  300. {
  301. sql.Append("'");
  302. sql.Append(ds.Tables[0].Rows[i].ItemArray[j]);
  303. sql.Append("'");
  304. sql.Append(" , ");
  305. }
  306. sql.Length -= 2;
  307. sql.Append(");");
  308. OleDbCommand sqlQuery1 = new OleDbCommand(sql.ToString(), con);
  309. sqlQuery1.ExecuteNonQuery();
  310.  
  311. }
  312. con.Close();
  313.  
  314. }
  315. }*/
  316. //77777777777777777777777777777777777777777
  317. /*using System;
  318. using System.Xml;
  319. using System.Data;
  320. using System.Data.OleDb;
  321. namespace ReadingXML2
  322. {
  323. class Class1
  324. {
  325. static void Main(string[] args)
  326. {
  327. // create a connection
  328. OleDbConnection con = new OleDbConnection();
  329. con.ConnectionString =
  330. "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Users\\Yan\\Desktop\\BiBD-6lab\\BIBD\\BIBD4\\my.mdb";
  331. // create a data adapter
  332. OleDbDataAdapter da = new OleDbDataAdapter("Select * from tovary", con);
  333. // create a new dataset
  334. DataSet ds = new DataSet();
  335. // fill dataset
  336. da.Fill(ds, "tovary");
  337. // write dataset contents to an xml file by calling WriteXml method
  338. ds.WriteXml("C:\\Users\\Yan\\Desktop\\BiBD-6lab\\BIBD\\BIBD4\\OutputXML.xml");
  339. }
  340. }
  341. }*/
  342. //88888888888888888888888888888888888888888888888888888888888888888888888888
  343.  
  344. //99999999999999999999999999999999999999999999999999999999999999999999999999
  345. /*using System.Data;
  346. using System.Data.OleDb;
  347. using System.Drawing;
  348. using System.Linq;
  349. using System.Text;
  350. using System.Xml.Linq;
  351. using System.Xml;
  352. using System.IO;
  353.  
  354. using System;
  355. using System.Xml.XPath;
  356.  
  357. class XMLtoACCESS
  358. {
  359. static void Main(string[] args)
  360. {
  361. bool bl = false;
  362. XDocument myXML = XDocument.Load("C:\\Users\\Yan\\Desktop\\BiBD-6lab\\BIBD\\BIBD4\\Product.xml");
  363. foreach (XElement el in myXML.Root.Elements("Product"))
  364. {
  365. if (el.Element("id").Value == "1")
  366. {
  367. //el.remove;
  368. el.SetElementValue("price", "200");
  369. el.SetElementValue("count", "1000");
  370. Console.WriteLine(el);
  371. bl = true;
  372. }
  373. }
  374. if (bl) myXML.Save("C:\\Users\\Yan\\Desktop\\BiBD-6lab\\BIBD\\BIBD4\\Product.xml");
  375. }
  376. }*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement