-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
59 lines (53 loc) · 1.66 KB
/
Program.cs
File metadata and controls
59 lines (53 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System;
using System.Data;
using System.IO;
using System.Text;
using System.Xml;
using MySql.Data.MySqlClient;
namespace XMLDataTest
{
class Program
{
static void Main(string[] args)
{
DatabaseController dc = new DatabaseController();
if(!dc.TryConnectToDatabase())
return;
if (args.Length > 0)
{
dc.SetTable(args[0]);
}
else
{
dc.SetTable("ITEM");
}
DumpTableToXML(dc, "output");
if (!dc.TryCloseConnection())
return;
}
/// <summary>
/// Using the provided database information, this method dumps the current table to an xml file.
/// </summary>
/// <param name="dc">the database we use</param>
/// <param name="filename">the name of the file with no extension</param>
private static void DumpTableToXML(DatabaseController dc, string filename)
{
DataTable dataTable;
using (MySqlDataReader reader = dc.GetReader())
{
dataTable = reader.GetSchemaTable();
dataTable.Load(reader);
}
XmlTextWriter xmlTWriter = new XmlTextWriter(Directory.GetCurrentDirectory() + "\\" + filename + ".xml", Encoding.Default);
xmlTWriter.Formatting = Formatting.Indented;
try
{
dataTable.WriteXml(xmlTWriter, true);
}
catch (Exception e)
{
Console.WriteLine("Error: " + e.Message);
}
}
}
}