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 6799065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:48:14+00:00 2026-05-26T18:48:14+00:00

I am working on a project, and I have hit a brick wall. My

  • 0

I am working on a project, and I have hit a brick wall. My code adds dates with a type to a database, but I need to create an error when there is already a similar entry within the code. However, I cannot get my loop to check for duplicates, and instead it adds duplicates! I am not very good at loops so I’m a bit stuck at this. Any help to check for duplicate entries and to stop it from creating too many would be a great help! Changed my code within this text area so it’s not exactly the same variable names.

Here is my code: –

if (DT != null && DT.Length > 0 || DF != null && DF.Length > 0)
            {
                for (int t = 0; t < Type.Length; t++)
                {
                    DateTime checkDate;

                    if (Type.IsSelectionValid(8, out typeError) && DateTime.TryParse(DF, out typeError) && DateTime.TryParse(DT, out checkDate))
                    {
                            TypeValid = true;
                            error.Error = false;
                        }
                        else
                        {
                            error.Errors = "Type-Invalid";
                            absenceTypeValid = false;
                            break;
                        }
                    }
                    else
                    {
                        error.Errors = "Type-Duplicate";
                        TypeValid = false;
                        break;
                    }
                }
            }
  • 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-26T18:48:15+00:00Added an answer on May 26, 2026 at 6:48 pm

    I’m ‘fairly’ sure you are going out of your way to make a problem more difficult than it is here, but I can’t say for sure since I’m not entirely sure what this is doing.

    But here are the conditions that need to be met to get to your Type-Duplicate Error line:

    1) Either DT or DF have to not be empty to get past the first if statement

    2) Either IsSelectionValid() has to return false or either DT or DF have to be an invalid DateTime.

    None of those things constitute a duplicate.

    Let me try to explain what I see here:

    I first see variables called DT, DF. I can see these are dates, but that’s all I know about them. I see ‘Type’ which I understand even less about than DT and DF. I see that you are doing a loop for Type.Length number of iterations… but what does this mean to me if I don’t have a clue what Type is?

    If you had comments explaining what things are I ‘might’ be able to help you, but there’s just really not enough information to know what’s happening here.

    If you simply want to know how to avoid adding duplicates to a database, then I would suggest adding a constraint or index to the column in the database and then you can just catch the exceptions that are thrown when you try to insert a duplicate and deal with it that way. Alternatively, account for it in your insert statement.

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

Sidebar

Related Questions

I'm currently working on a project Euler problem (www.projecteuler.net) for fun but have hit
I am working on a project and have the following psuedocode: // create a
I am working on a project where I have to create a chain with
I'm working on my iOS project again. However, I seem to have hit a
I'm currently working on my first Django project and have hit a roadblock in
I am working on a project in which I need to create a form
I've hit a minor brick wall here in Visio. I've got a project that
I'm working my way through this tutorial here about progress dialogues but have hit
I'm working on a small ASP.NET project and just hit a wall. In a
In the project I am currently working on, we have the need to develop

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.