3

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?

kev
  • 135
  • 1
  • 4
  • 14

2 Answers2

3

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.

Matthew Brubaker
  • 3,097
  • 1
  • 21
  • 18
-1

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

Muhammad Akhtar
  • 51,913
  • 37
  • 138
  • 191
  • Thanks very much for the suggestion. However, this is not what I mean. What I am looking for is a way to NOT have to specify the max length, such that if I later wanted to change the maxlemgth in the database, that I wouldn't have to recompile the code. – kev Jul 12 '11 at 09:13