• 0

[C#] MaxLength violated on Column in IDataAdapter.Fill Implementation


Question

I am implementing IDataRecord, IDataReader and IDataAdapter to add, modify and delete records in a proprietary flat-file structure in which I have the source code to. I have a working implementation with classes I wrote to access the data but I am trying to write something more universally useful.

 

That being said, I am running into an ArgumentException ("Cannot set column 'Header_Checksum'. The value violates the MaxLength limit of this column."). The error SEEMS concise and useful but the MaxLength on the column is set to 11. 11 being far more bytes than Int32 takes up and more digits than Int32 contains. The only Constraint on the table is the PK which is at the end ("RecordPosition").

 

Any ideas on where to look next? Everything works fine if I disable EnforceConstraints but I'd like to keep that enabled for sanity sake if I can.

 

Attached is a screenshot with a watch on the offending value and the DataColumn properties.

visualStudioPlez-MaxLengthViolatedButNotReally.png

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

I believe I have solved this issue.

 

MaxLength was defined on a type for which it should not have been. It applies to string-types only and I had it defined on an Int32. Setting the MaxLength to -1 when it is not typeof(string) in my FillSchema fixed the issue for me.

Link to comment
Share on other sites

This topic is now closed to further replies.