I tend to agree with jcollum on this one, using a Typed Dataset at runtime is probably the wrong way to go. If on the other hand, you just want to be able to get structured data ( aka, a DataTable ) from a database at runtime, you could use reflection to create a TableAdapter from an arbitrary data result.
var results = (from data in db.SomeTable select data).ToArray();
DataTable dt = ObjectArrayToDataTable(results);
// At this point you have a properly structure DataTable.
// Here is your XSD, if absolutely needed.
dt.WriteXMLSchema("c:\somepath\somefilename.xsd");
private static System.Data.DataTable ObjectArrayToDataTable(object[] data)
{
System.Data.DataTable dt = new System.Data.DataTable();
// if data is empty, return an empty table
if (data.Length == 0) return dt;
Type t = data[0].GetType();
System.Reflection.PropertyInfo[] piList = t.GetProperties();
foreach (System.Reflection.PropertyInfo p in piList)
{
dt.Columns.Add(new System.Data.DataColumn(p.Name, p.PropertyType));
}
object[] row = new object[piList.Length];
foreach (object obj in data)
{
int i = 0;
foreach (System.Reflection.PropertyInfo pi in piList)
{
row[i++] = pi.GetValue(obj, null);
}
dt.Rows.Add(row);
}
return dt;
}
You could apply the same principal to create a structured DataSet and easily create a DataAdapter to it.
Or perhaps I am mis-reading your requirements.