CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2016
    Posts
    6

    validating textboxes before opening database

    I need an advanced validation to validate entries in textboxes even before it opens the database to check entries or input in database

    I am creating a database which should allow no empty names or not valid email addresses but my program validates alright but opens the database and inputs the wrong data even after collecting errors

    Any help would be much appreciated

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: validating textboxes before opening database

    What have you done so far?

  3. #3
    Join Date
    Mar 2016
    Posts
    6

    Re: validating textboxes before opening database

    should i post the the whole code here pls ???

  4. #4
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: validating textboxes before opening database

    Whatever code or problem you are struggling with, please post it with proper explanation

  5. #5
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: validating textboxes before opening database

    Without seeing your validation code and the code that goes on to save the data there is no way to be sure exactly what you have done but it sounds like you are using some conditional checks to see if the data is empty and perhaps valid but then continue on to the save regardless of that result. One simple solution may be to use a flag [i.e. a boolean var at the top of the routine] make sure that it is false at the top of the routine then if any of the validation fails set the flag to true.

    When you get to the code that would save the data wrap that in a conditional statement that checks the state of the flag and saves only if the flag is still false at that point.

    Code:
    dim Failed as Boolean
        If Text1.Text=vbnullstring then 
            failed=true
            'display message if desired
        End If
        If Text2.Text=vbnullstring then 
            failed=true
            'display message if desired
        End If
        ' continue with whatever validations are needed.
    
    If Not Failed then
        'save your data
    End If
    Now of course this assumes that all the validation and the save code are in the same routine. If they are in different routines then the boolean var needs to be defined at the top of the code for the form or in a module and if in a module may need to be public.
    Also if the boolean is defined outside the routine then the first thing that needs to happen is to set the boolean to false before you begin the validations
    Always use [code][/code] tags when posting code.

  6. #6
    Join Date
    Mar 2016
    Posts
    6

    Re: validating textboxes before opening database

    Thank you very much

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured