Search   

Sunday, February 05, 2012

Support » Support Forum

Register  Login

 Menu  
 
    

 Welcome!  
 


Welcome to the NDO support forum!

kreis.gif Please register/login at the site if you want to post a thread. We sometimes copy support mails of common interest to the forum. They appear with anonymous sender.
kreis.gif Please post your messages in English language if possible. You can do your posts also in German, we will translate your post and our answer so that all users of the forum can read your posts.
kreis.gif The forum software requires that javascript is enabled.
kreis.gif Please do not insert licence information or licence keys in forum posts.
kreis.gif If you know a good answer to a post of another user, feel free to reply!
kreis.gif The forum is monitored. We reserve the right to remove posts we consider not to be useful for other forum users.

   Print   

      
 NDO Support Forum  
 
SearchForum Home
  NDO-Forum postings in english please, if possible.  Developing with NDO  How to Determin...
 How to Determine String Field Lengths
 
 5/16/2006 1:04:59 PM
anonymous
20 posts


How to Determine String Field Lengths
Hi all, TextBoxes have the property MaxLength. It it somehow possible with NDO to read the db column length for a certain string field and transfer it to MaxLength? That should keep the user for example from entering the full company name if half of it would be cut of after saving. Manually entering the field length appears uncomfortable and error prone to me. Thanks in advance! C.R.
 5/16/2006 1:15:29 PM
Mirko
109 posts
5th


Re: How to Determine String Field Lengths
 Modified By admin  on 5/16/2006 1:19:30 PM)

Hi C.
Below you find are some recommendations how to cope with it.
Best Regards,
Mirko Matytschak

// Determine the max length of the field firstName of the class Employee using NDO.Mapping;
.....
PersistenceManager pm = new PersistenceManager();
NDOMapping mapping = pm.NDOMapping;
Class cl = mapping.FindClass(typeof(Employee));
int length = cl.FindField("firstName").ColumnLength;
// If no length is determined in the mapping file, use the default for the database
if (length == 0) 
  length = cl.Provider.GetDefaultLength(typeof(string)); // Normally 255
// Optional you can iterate over all mapped fields:
foreach(Field field in cl.Fields)
{
  myTextBoxes[field.Name].MaxLength = field.ColumnLength;
  // assumes a field length for each field -
  // otherwise use GetDefaultLength like above
}

// This is, how you get myTextBoxes:
Hashtable myTextBoxes = new Hashtable();
foreach(Control c in myForm.Controls)
{
  if (c is TextBox)
    myTextBoxes.Add(c.Name.Replace("text", string.Empty), c);
}

// Here we assume, you have a naming convention
// like firstName -> textFirstName
// so take care of the upper/lower case first letter

  NDO-Forum postings in english please, if possible.  Developing with NDO  How to Determin...
  SearchSearch  Forum HomeForum Home