Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6901817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:43:15+00:00 2026-05-27T07:43:15+00:00

I am trying to validate fields so user can’t have entered data with empty

  • 0

I am trying to validate fields so user can’t have entered data with empty fields. The problem is that I am still adding empty fields, so my validation isn’t working.

First, I am checking is type is selected from a combo box. Then I am checking if which type user picked, and then depending on the type I am checking a fields for empty string before entering a data.

Did I miss something here?

private void btnAddEntry_Click(object sender, EventArgs e)
{
    // Multiple level field validations.
    if (cmbType.SelectedIndex != -1)
    {
        if (cmbType.SelectedIndex == 0 && 
            (txtUserName.Text != string.Empty || 
            txtPassword.Text != string.Empty))
        {
            string SQL =
                "INSERT INTO PersonalData([Type], [UserName], [Password]) " +
                "VALUES(@Type, @UserName, @Password)";

            InsertData(SQL);
        }
        else if (cmbType.SelectedIndex == 1 && 
            (txtURL.Text != string.Empty || 
            txtUserName.Text != string.Empty || 
            txtPassword.Text != string.Empty))
        {
            // Creating SQL string. Using [] will prevent any erros
            // that might occur if any other names will be reserved words.
            string SQL =
                "INSERT INTO PersonalData([Type], [URL], [UserName], [Password]) " +
                "VALUES(@Type, @URL, @UserName, @Password)";

            InsertData(SQL);
        }
        else if (cmbType.SelectedIndex == 2 && 
            (txtSoftwareName.Text != string.Empty || 
            txtSerialCode.Text != string.Empty))
        {
            // Creating SQL string. Using [] will prevent any erros
            // that might occur if any other names will be reserved words.
            string SQL =
                "INSERT INTO PersonalData([Type], [SoftwareName], [SerialCode]) " +
                "VALUES(@Type, @SoftwareName, @SerialCode)";

            InsertData(SQL);
        }
        else
        {
            lblMessage.Text = "Please fill out all required fields!";
        }
    }
    else
    {
        lblMessage.Text = "Please select a type first!";
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T07:43:16+00:00Added an answer on May 27, 2026 at 7:43 am

    Are you sure you want to or the potential fields and not and them?
    For instance,

    else if (cmbType.SelectedIndex == 1 && 
        (txtURL.Text != string.Empty && 
        txtUserName.Text != string.Empty && 
        txtPassword.Text != string.Empty))
    

    Will only allow you to insert the data if the url, username and password have a value – using the or’s only one of those values needs to be filled in before the insertion is called, meaning you could have a valid url but no password and username entered.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to validate a User Profiling form in django and I can't.
I'm trying to user jQuery Validation plugin to validate a signup form, but I
I was trying to validate my User model data and I came upon this
I am trying to get jquery validate to work on multiple fields. Reason being
I'm trying to validate a input field with the JQuery validation plugin. The numeric
I am trying to validate user id's matching the example: smith.jack or smith.jack.s In
I'm trying to validate that a submitted URL doesn't already exist in the database.
I'm trying to validate user input, which is just comma separated numbers. I'd like
I'm trying to validate the following XML but I'm unable to, can you please
I was trying to validate an XML signature. The validation according to this tutorial

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.