开发者

How to ignore MaxLength constraint on an ADO.NET Datatable.DataColumn when loading data

开发者 https://www.devze.com 2023-03-19 15:48 出处:网络
A recurring problem in my experience when using Datasets and DataTables is that changing the database schema after the Dataset is compiled and released will cause constraint checking to fail. Of cours

A recurring problem in my experience when using Datasets and DataTables is that changing the database schema after the Dataset is compiled and released will cause constraint checking to fail. Of course, this is generally a good thing.

However, sometimes I would like a bit of flexibility here. I would usually like it to ignore the DataColumn.MaxLength constraint.

In this scenario, I could compile my dataset to have a datatable for TableA where Column1 is a String of MaxLength 20开发者_开发百科. Then, months later, I decide that a max length of 100 would be more appropriate. If I change the definition of TableA.Column1 in the datbase from varchar(20) to varchar(100), it would be nice that when I call a DataAdapter to Fill() this DataTable, that it might just not worry about these new longer values in Column1.

My current code would throw an exception. Is there a way to write the code so that this would would be ignored?


Set the max length attribute on the columns you want to ignore to -1. This will clear the max length constraint and you will not have that issue any more.


Follow the below steps and change the Max Length of DataTable FieldName

Go to your DataSet --> DataTable --> Go to properies of Field --> Change the Max length

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号