Validation before saving entity

Posts   
 
    
shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 28-Apr-2010 17:23:24   

Hi

I have successfully started off crating project with LLBLGEN without much of problems.

I have small trouble.

Let us say my table employee has a column named as employee name and length varchar2(100).

Now, from UI, user may enter the employee name longer than 100 characters. This runs into error.

How can I validate the input with column length to ensure user has not entered more than 100 characters ?

Do I have to use another template for generating the validation class. If yes which one and how do I use it after generation?

Shekar

Walaa avatar
Walaa
Support Team
Posts: 14994
Joined: 21-Aug-2005
# Posted on: 28-Apr-2010 17:51:26   

Checking the length of a string field is already built-In (Built-In Validation). You need to do nothing about it.

shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 29-Apr-2010 05:59:24   

Hi, Well I did try your suggestion. But it runs into overflow error when input length is more than desired length. I want to trap the error when user exceeds the length of input and display an error provider to user stating user has entered more value length than the required value length. How can I achieve this ?

Example Code: var accountnatureadapter = new DataAccessAdapter(); var accountnature = new AccountnatureEntity();

        accountnature.Description = tbxdescription.Text;
        accountnature.Createddate = DateTime.Now;
        accountnature.CreateduserId = 1;

        #endregion

        if (accountnatureadapter.SaveEntity(accountnature, true)) // Insert Data
        {
            message = ClubCentricBISpecific.Generic.datasavesuccess;  // Message
            ClubCentricBISpecific.Generic.ClearForm(this); 

        }
        else
        {
            message = ClubCentricBISpecific.Generic.datasavefailure; // Message
        }

        MessageBox.Show(message); 

Here user should not enter more than 100 characters for field tbxdescription.Text. but if he does so, it goes into runtime error. But I want to use the error provider to display message to user that more than 100 characters are not permitted.

Walaa avatar
Walaa
Support Team
Posts: 14994
Joined: 21-Aug-2005
# Posted on: 29-Apr-2010 11:04:24   

You should set the MaxLength of the textBox to the maxLength of the field, as mentioned here: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=7184

I think this is a better approach.

shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 29-Apr-2010 12:49:10   

Great ! Excellant Support team.

No wonder why LLBGLGEN is superior over other products.

Any thing I ask I get an answer in less than 24 hours ! hats off !