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

  • Home
  • SEARCH
  • 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 6944329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:17:35+00:00 2026-05-27T13:17:35+00:00

I am using an ASP.NET wizard control for editing the role of the user

  • 0

I am using an ASP.NET wizard control for editing the role of the user after showing its information. The wizard consists of three steps:

Hello everybody,

  • First Step: contains a textbox where the admin will put the username of the user
  • Second Step: it will show the information of the user
  • Third Step: it is for editing the role of the user

Since I am developing an intranet web application for the company, the Admin doesn’t need to know if the user is on the database or not. So I want the system automatically to check in the background if the user is on the database or not. If he is in the database, the role will be edited for him immediately. If he is not in the database, his information will be added to the system with giving him a role.

protected void Wizard1_FinishButtonClick(object sender, WizardNavigationEventArgs e)
{
        //If one of the items is selected AND a username exists in the Username session object update the user role
        string username = TextBox1.Text;

        if (!String.IsNullOrEmpty(radio1.SelectedValue) && !String.IsNullOrEmpty(username))
        {
            string connString = "Data Source=localhost\\sqlexpress;Initial Catalog=psspdb;Integrated Security=True";

            string insertUserCommand = "INSERT INTO employee (Name, Username, JobTitle, BadgeNo, EmpOrgType, DivisionCode) values (@Name, @Username, @JobTitle, @BadgeNo, @EmpOrgType, @DivisionCode)";
            string cmdText = "SELECT Count(*) FROM employee WHERE Username = '" + username + "'";

            using (SqlConnection conn = new SqlConnection(connString))
            {
                conn.Open();
                // Open DB connection.
                using (SqlCommand cmd = new SqlCommand(cmdText, conn))
                {
                    if ((int)cmd.ExecuteScalar() == 0){
                        //An object from ObjectUser class to get the user information from the secure system and insert them to the database
                        ObjectUser user = new ObjectUser(username,true);

                        SqlCommand cmd2 = new SqlCommand(insertUserCommand, conn);
                        cmd2.Parameters.AddWithValue("@Name", user.Name);
                        cmd2.Parameters.AddWithValue("@Username", username);
                        cmd2.Parameters.AddWithValue("@JobTitle", user.GetProperty("EMP_TITLE"));
                        cmd2.Parameters.AddWithValue("@BadgeNo", user.GetProperty("EMP_BADGE_NUMBER"));
                        cmd2.Parameters.AddWithValue("@EmpOrgType", user.GetProperty("EMP_EMPTYPE"));
                        cmd2.Parameters.AddWithValue("@DivisionCode", user.Org.Division.SapCode);
                    }

                }
            }

            string deleteCommand = "DELETE FROM UserRole where Username=@Username";
            string insertCommand = "INSERT INTO UserRole (RoleID,Username) values(@RoleID,@Username)";
            using (SqlConnection conn = new SqlConnection(connString))
            {
                conn.Open();
                //using (SqlCommand cmd = new SqlCommand(cmdText, conn))
                using (SqlCommand cmd = new SqlCommand(deleteCommand, conn))
                {
                    cmd.Parameters.AddWithValue("@Username", username);
                    cmd.ExecuteNonQuery();
                    //Now the insert
                    cmd.CommandText = insertCommand;
                    cmd.Parameters.Clear(); //need this because still has params from del comm
                    cmd.Parameters.AddWithValue("@RoleID", radio1.SelectedValue);
                    cmd.Parameters.AddWithValue("@Username", username);
                    cmd.ExecuteNonQuery();
                    //infoSpan.InnerText = String.Format("The users role has been updated to - {0}", radio1.SelectedValue);
                    //cmd.ExecuteScalar();
                    //infoSpan.InnerText = String.Format("The users role has been updated to - {0}", radio1.SelectedValue);
                }
            }

            Wizard1.Visible = false;
            wizard.InnerHtml = @"The task has been done successfully. <br /> <a href='UserManagement.aspx'>Edit Another User</a>";
        }


    }

Now for the user who is not in the database, when I chose a role for him and click Finish button, it should be added to the database but in my case I got an error in the bottom of the browser which says (Error on page), when I clicked on it, I got the following details:

Sys.WebForms.PageRequestMangerServerErrorException: The INSERT statement conflicted with the FOREIGN KEY constraint
“FK_UserRole_employee”. The confilct occurred in database “psspdb”
table “dbo.employee”, column ‘Username’. The statement has been
terminated.

I don’t how to fix it. Any help please?

FYI, the design of the database is like this:

employee table:

Username, Name, JobTitle...

UserRole table:

UserRoleID, Useranme, RoleID

Roles table:

RoleID, RoleName

The first attribute is the primary key for each table.

BTW, As you see in my question above, I am using something called insertUserCommand. This command should be enough to add the user information to the database. So I should not have this conflict. Sorry for asking a lot but I am beginner in this area. Could you please tell me what I should do with code?

  • 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-27T13:17:35+00:00Added an answer on May 27, 2026 at 1:17 pm
    You are not executing insertUserCommand.After adding parameter that means after
    cmd2.Parameters.AddWithValue("@DivisionCode", user.Org.Division.SapCode);
    write cmd2.ExecuteNonQuery().
    As you are not executing it this entry will not add to table
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET form with multiple steps (using the Wizard control). When advancing
Using Asp.Net MVC3, I have many steps in a wizard where after every step
I want to hide the Next button on my ASP.NET Wizard control using JavaScript.
i have read somewhere about using layout template in asp.net wizard control but when
I'm using ASP.NET, and in a Wizard control I have radio buttons where if
I am building a wizard using asp.net mvc. currently when the user hits next
I am using the create user wizard of C# asp.net 4. I want to
Using ASP.NET 3.5 and jQuery UI. When a user clicks the Search button, a
Using asp.net 3.5 Gridview control, visual studio 2008. I have played with all the
Using ASP.NET MVC when trying to get the information stored on my Session[objectName] from

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.