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

Recommended Posts

Squirrelington    30

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.


Share this post

Link to post
Share on other sites
Squirrelington    30

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.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.