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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:44:51+00:00 2026-05-31T22:44:51+00:00

I have a small problem that takes me for a day and until now

  • 0

I have a small problem that takes me for a day and until now it is not resolve, I am trying to save a record that is not existed in the database, if the user input was already existed, it will not save but the thing is it works somehow but then I notice when i tried to validate the 2nd row and input the same values like username or email boom! the data was inserted so it cause duplicates. How to fix this? can you help me please? thanks

here’s my code.

  protected void btnSubmit_Click(object sender, EventArgs e)
    {
        lblInternetAccount.Value = lblAccountNo.Text.ToString() + txtUsername.Text.ToString();
        DataSet ds = new DataSet();
        ds = (startWebService.getAllUsers());
        if (ds.Tables[0].Rows.Count > 0)
        {
            foreach (DataRow drow in ds.Tables[0].Rows)
            {
                string username = drow["UserName"].ToString();
                string acctNo = drow["AccountNumber"].ToString();

                if (username != txtUsername.Text.ToString() || acctNo != lblAccountNo.Text.ToString())
                {
                    startWebService.insertUser(lblAccountNo.Text.ToString(), txtUsername.Text.ToString(), txtPassword.Text.ToString(), txtUsername.Text.ToString(), cboQuestion.Text.ToString(), txtAnswer.Text.ToString(), lblInternetAccount.Value.ToString(), txtPassword.Text.ToString());
                    lblMessage.Text = "Record Updated!";

                }
                else
                {
                    lblMessage.Text = "<br>Unable to create record because account number/email is already registered.Please login instead.<br><br>";

                }
            }
        }
    }

web services:

    private DataSet GetDataSet(string strSPROC)
    {

        SqlConnection conn = new SqlConnection(connectionString);
        SqlCommand cmd = conn.CreateCommand();
        cmd.CommandText = strSPROC;
        conn.Open();
        SqlDataAdapter myDataAdapter = new SqlDataAdapter();
        myDataAdapter.SelectCommand = cmd;
        DataSet dsMT = new DataSet();
        myDataAdapter.Fill(dsMT);
        return dsMT;
        conn.Close();
    }
   [WebMethod]
    public void insertUser(string accountNo, string userName, string pAssword, string eMail, string secretQuestion, string secretAnswer,string onlineActNo,string acctkey)
    {
        Insert("ELMS_CREATEMEMBER", accountNo, userName, pAssword, eMail, secretQuestion, secretAnswer, onlineActNo,acctkey);
    }
  • 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-31T22:44:52+00:00Added an answer on May 31, 2026 at 10:44 pm

    You were almost there. You just perform the actual insert to early (which will lead to many inserts).

    What you’re doing is this:

    for each existing record ->
    if record does not match new record ->
    insert new record

    What you need to do is first check all existing records and only then, when no record matched your new record, insert the new record.

    A modified code example:

    lblInternetAccount.Value = lblAccountNo.Text.ToString() + txtUsername.Text.ToString(); 
    DataSet ds = new DataSet(); 
    ds = (startWebService.getAllUsers()); 
    
    bool isDuplicated = false;
    if (ds.Tables[0].Rows.Count > 0) 
    { 
        foreach (DataRow drow in ds.Tables[0].Rows) 
        { 
            string username = drow["UserName"].ToString(); 
            string acctNo = drow["AccountNumber"].ToString(); 
    
            if (username == txtUsername.Text.ToString() && acctNo == lblAccountNo.Text.ToString()) 
            { 
                isDuplicated = true;
            } 
    
        } 
    
        if (!isDuplicated)
        {
            startWebService.insertUser(lblAccountNo.Text.ToString(), txtUsername.Text.ToString(), txtPassword.Text.ToString(), txtUsername.Text.ToString(), cboQuestion.Text.ToString(), txtAnswer.Text.ToString(), lblInternetAccount.Value.ToString(), txtPassword.Text.ToString()); 
            lblMessage.Text = "Record Updated!"; 
        }
        else 
        { 
            lblMessage.Text = "<br>Unable to create record because account number/email is already registered.Please login instead.<br><br>"; 
        } 
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a small Cocoa problem. I have a StatusBar application that has an
I have a small problem, but I hope somebody can help. Let's say that
Let's say you have a small calculator program that takes numbers and an operator
Hello to all that read I have a small problem(or it could be large!),
I have this small PHP script that takes a POST variable and writes it
have small problem, and would very much appreciate help :) I should convert byte
I have small problem with my .net 2.0 winforms application. I want to embed
I have a small problem with interfaces. Here it is in Pseudo code :
I have a small problem with a script. I want to have a default
I have a small problem with how should i think a... problem. I want

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.