使用DataAdapter动态设置DataColumn的MaxLength属性 [英] Dynamically setting MaxLength property of a DataColumn with DataAdapter
问题描述
所以我googled了一段时间,发现 DataAdapter 除了填充
之外还有另一种方法,它是: FillSchema(),其中包含数据库模式到 DataTable
中。由于我想要的是 MaxLength 属性我做的是将模式加载到另一个表中,并循环遍历分配给每个值的列。
当然,如果你想保留所有的约束数据库在表中,那么你不需要循环,只需将模式加载到datatable。
I have a datatable that I'm filling with SqlDataAdapter.Fill(). Is there a way to dynamically assign the MaxLength
property to each string datacolumn to the maximum allowed by that column in the database?
So I googled for a while and found that the DataAdapter has another method besides Fill
which is: FillSchema(), which includes the database schema into the DataTable
. Since all I wanted to bring was the MaxLength property what I did was load the schema into another table and loop through the columns assigning the value to each one.
Of course if you wanted to keep all the constraints in the database within your table, then you'd need no loop and just load the schema into the datatable.
这篇关于使用DataAdapter动态设置DataColumn的MaxLength属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!