Sigh. Anyhow, pat, if you can, I strongly advise you to stay clear of the DataSet class and make something real. I personally used .NET's xml classes to load the content and parsed it myself, storing it in my *own* variables and not some abstract DataSet crap.
That way you can define a struct, for example something like:
public class MyDatabase
{
public List<TableStruct> Tables;
public MyDatabase()
{
this.Tables = new List<TableStruct>();
}
public void AddTable(TableStruct table)
{
this.Tables.Add(table);
}
}
public struct TableStruct
{
public List<ColumnStruct> Columns;
public List<RowStruct> Rows;
public TableStruct(int numCols)
{
this.Columns = new List<ColumnStruct>(numCols);
this.Rows = new List<RowStruct>();
}
}
public struct ColumnStruct
{
public string Name;
public ColumnType Type;
public int MaxLength;
public ColumnStruct(string name, ColumnType type, int length)
{
this.Name = name;
this.Type = type;
this.MaxLength = length;
}
}
public struct RowStruct
{
public List<object> Fields;
public RowStruct(params object[] data)
{
this.Fields = new List<object>();
this.Fields.AddRange(data);
}
}
public enum ColumnType
{
TINYINT,
SMALLINT,
MEDIUMINT,
INT,
BIGINT,
FLOAT,
DOUBLE,
DOUBLE_PRECISION,
REAL,
DECIMAL,
NUMERIC,
DATE,
DATETIME,
TIMESTAMP,
TIME,
YEAR,
CHAR,
VARCHAR,
TINYBLOB,
TINYTEXT,
BLOB,
TEXT,
MEDIUMBLOB,
MEDIUMTEXT,
LONGBLOB,
LONGTEXT,
ENUM,
SET
}
private static MyDatabase db;
static void Main(string[] args)
{
db = new MyDatabase();
// Then do something like this in a foreach loop through your xml content:
TableStruct curtab = new TableStruct(2);
curtab.Columns.Add(new ColumnStruct("id", ColumnType.SMALLINT, 65535));
curtab.Columns.Add(new ColumnStruct("str", ColumnType.VARCHAR, 255));
curtab.Rows.Add(new RowStruct(0, "hello"));
curtab.Rows.Add(new RowStruct(1, "world"));
curtab.Rows.Add(new RowStruct(2, "lol"));
db.AddTable(curtab);
}
Then you'd have something like:
DATABASE
|
|
|- TABLE
|-------| SMALLINT(65535) id | VARCHAR(255) str |
| |--------------------|------------------|
| | 0 | hello |
| | 1 | world |
| | 2 | lol |
| |--------------------|------------------|
|
-
Of course, you could add more tables onto the end with MyDatabase.AddTable(), until you have all the tables with their respective data loaded into the MyDatabase.
After that you can do something like:
StringBuilder outstr = new StringBuilder();
foreach (TableStruct tab in db.Tables)
{
foreach (RowStruct row in tab.Rows)
{
foreach (object ob in row.Fields)
{
outstr.Append(ob.ToString());
outstr.Append(',');
}
outstr.Append("\n");
}
oustr.Append("----\n");
}
Which would produce something like:
0,hello
1,world
2,lol
----
Of course the exact implementation would be a lot different, and you'd have to escape the strings and whatnot. Still it's just a _general_ idea on how I'd do it.
Note: Wrote all this on the posting page, so none of it is tested. Not sure how good it'll work lol.