我是这样做的:
String dateFilter = "IIF([data_type] = 'smalldatetime', 'true!', '')";
String targetFilter = "[source_field]";
DataTable tempDataTable = new DataTable();
//create fields field
DataColumn order = new DataColumn("order", Type.GetType("System.Int32"));
tempDataTable.Columns.Add(order);
order.AutoIncrement = true;
order.AutoIncrementSeed = 1;
order.ReadOnly = false;
_sourceDataAdapter.Fill(tempDataTable);
tempDataTable.Columns.Add(new DataColumn("date_format", Type.GetType("System.String"), dateFilter));
tempDataTable.Columns.Add(new DataColumn("target_field", Type.GetType("System.String"), targetFilter));
tempDataTable.BeginInit();
tempDataTable.EndInit();
_dataTable.Columns.Add(new DataColumn("order", Type.GetType("System.Int32")));
_dataTable.Columns.Add(new DataColumn("local_field", Type.GetType("System.String")));
_dataTable.Columns.Add(new DataColumn("length", Type.GetType("System.Int32")));
_dataTable.Columns.Add(new DataColumn("data_type", Type.GetType("System.String")));
_dataTable.Columns.Add(new DataColumn("decimals", Type.GetType("System.Int32")));
_dataTable.Columns.Add(new DataColumn("date_format", Type.GetType("System.String")));
_dataTable.Columns.Add(new DataColumn("target_field", Type.GetType("System.String")));
using (DataTableReader reader = tempDataTable.CreateDataReader())
{
while(reader.Read())
{
if (reader.HasRows)
{
_dataTable.Rows.Add(reader.GetValue(0), reader.GetValue(1), reader.GetValue(2), reader.GetValue(3), reader.GetValue(4), reader.GetValue(5), reader.GetValue(6));
}
}
}
}