Dynamically setting MaxLength property of a DataColumn with DataAdapter

只愿长相守 提交于 2019-12-13 03:44:51

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/6859615/dynamically-setting-maxlength-property-of-a-datacolumn-with-dataadapter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!