public DataTable CreateTable(string tableName, string fieldList) { DataTable dt = new DataTable(tableName); DataColumn dc; string[] Fields = fieldList.Split(','); string[] FieldsParts; string Expression; foreach (string Field in Fields) { FieldsParts = Field.Trim().Split(" ".ToCharArray(), 3); // allow for spaces in the expression // add fieldname and datatype if (FieldsParts.Length == 2) { dc = dt.Columns.Add(FieldsParts[0].Trim(), Type.GetType("System." + FieldsParts[1].Trim(), true, true)); dc.AllowDBNull = true; } else if (FieldsParts.Length == 3) // add fieldname, datatype, and expression { Expression = FieldsParts[2].Trim(); if (Expression.ToUpper() == "REQUIRED") { dc = dt.Columns.Add(FieldsParts[0].Trim(), Type.GetType("System." + FieldsParts[1].Trim(), true, true)); dc.AllowDBNull = false; } else { dc = dt.Columns.Add(FieldsParts[0].Trim(), Type.GetType("System." + FieldsParts[1].Trim(), true, true), Expression); } } else { return(null); } } if (ds != null) { ds.Tables.Add(dt); } return(dt); }