使用DataAdapter动态设置DataColumn的MaxLength属性 [英] Dynamically setting MaxLength property of a DataColumn with DataAdapter

查看:217
本文介绍了使用DataAdapter动态设置DataColumn的MaxLength属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个我用SqlDataAdapter.Fill()填充的数据表。有没有办法动态地将$ code> MaxLength 属性分配给每个字符串数据列数据到数据库中该列允许的最大值?

解决方案

所以我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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆