Cedar City Group: A long time requirement finally met...

Monday, December 17, 2007

A long time requirement finally met...

As long as I can remember, I have felt that when you use a text box to perform data entry for a database column, that the maxlength of the text box should match the definition of the column in the database. And that it should automatically change on the text box if the database design changed. I never had the gumption to actually write the code to do that, but I've always felt that it should be done.

I'm sitting here working on a fairly simple data entry form for a web application, I'm populating a text box with the value from a SubSonic field and that old urge to set the max length kicked in. I dug around in the SubSonic object model for a little bit and came up with the following code.


txtFirstName.Text = buyer.FirstName;
txtFirstName.MaxLength = buyer.GetSchema().GetColumn("firstname").MaxLength;



as my buddy Tim says Schweet!

0 comments: