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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:19:38+00:00 2026-06-10T20:19:38+00:00

I have a website I’m developing, and when a user creates an account I

  • 0

I have a website I’m developing, and when a user creates an account I want to store some additional info i have collected during the CreateUserWizard. When I run the code, i get an error when trying to write the data to a table I have created. I created the table in the ASPNETDB.mdf database (the one created by default) called UserProfile and has all the columns I’m trying to write to. In the web.config file I have:

<connectionStrings>
  <add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true"
  providerName="System.Data.SqlClient" />
</connectionStrings>

When the user creates an account, here is the code I have in the Creating_User event.

protected void RegisterUser_CreatingUser(object sender, LoginCancelEventArgs e)
    {
        //try
        //{
            string trimUserName = RegisterUser.UserName.Trim();
            if (RegisterUser.UserName.Length != trimUserName.Length)
            {
                accountlbl.Text = "The username cannot contain leading or trailing spaces.";
                accountlbl.Visible = true;
                //Cancel the created user info
                e.Cancel = true;
            }

            if (RegisterUser.Password.IndexOf(RegisterUser.UserName, StringComparison.OrdinalIgnoreCase) > 0)
            {
                accountlbl.Text = "The username may not appear anywhere in the password.";
                accountlbl.Visible = true;
                //Cancel the created user info
                e.Cancel = true;
            }


            String FirstName = ((TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("FirstName")).Text;
            String LastName = ((TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("LastName")).Text;
            String Company = ((TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("CompanyName")).Text;
            String PartsList = ((DropDownList)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("companyddl")).SelectedValue;
            String UserName = ((TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("UserName")).Text;
            String Password = ((TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("Password")).Text;
            String Email = ((TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("Email")).Text;
            String Question = ((TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("Question")).Text;
            String Answer = ((TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("Answer")).Text;
            // Insert a new record into User_Profile            
            if ((Company == "OurCompany" || Company == "OurCompany, Inc.") && PartsList == "")
            {
                Roles.AddUserToRole(UserName, "manager");
                UserRole = "manager";
            }
            if (PartsList == "SF")
            {
                Roles.AddUserToRole(UserName, "user_sf");
                UserRole = "user_sf";
            }
            if (PartsList == "TL")
            {
                Roles.AddUserToRole(UserName, "user_tl");
                UserRole = "user_tl";
            }
            if ((Company != "OurCompany" || Company != "OurCompany, Inc.") && PartsList == "")
            {
                Roles.AddUserToRole(UserName, "user");
                UserRole = "user";
            }

            // Get your Connection String from the web.config. ApplicationServices is the name I have in my web.config
            string connectionString = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
            string insertSql = "INSERT INTO UserProfile(FirstName, LastName, Company, PartsList, UserName, Password, Email, Question, Answer, UserRole)" +
                               "VALUES(@FirstName, @LastName, @Company, @Partslist, @UserName, @Password, @Email, @Question, @Answer, @UserRole)";
            using (SqlConnection myConnection = new SqlConnection(connectionString))
            {
                myConnection.Open();
                SqlCommand myCommand = new SqlCommand(insertSql, myConnection);
                myCommand.Parameters.AddWithValue("@FirstName", FirstName);
                myCommand.Parameters.AddWithValue("@LastName", LastName);
                myCommand.Parameters.AddWithValue("@Company", Company);
                myCommand.Parameters.AddWithValue("@PartsList", PartsList);
                myCommand.Parameters.AddWithValue("@UserName", UserName);
                myCommand.Parameters.AddWithValue("@Password", Password);
                myCommand.Parameters.AddWithValue("@Email", Email);
                myCommand.Parameters.AddWithValue("@Question", Question);
                myCommand.Parameters.AddWithValue("@Answer", Answer);
                myCommand.Parameters.AddWithValue("@Role", UserRole);
                myCommand.ExecuteNonQuery();  //ERROR HERE!!!//
                myConnection.Close();                    
            }
    }

I get an error on the myComman.ExecuteNonQuery(); statement saying — Must declare the scalar variable “@UserRole”.
If I comment out the code, it will not write anything to the database table. What am I doing wrong?

  • 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-06-10T20:19:39+00:00Added an answer on June 10, 2026 at 8:19 pm

    You have myCommand.Parameters.AddWithValue("@Role", UserRole);, but I think you should have myCommand.Parameters.AddWithValue("@UserRole", UserRole);.

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

Sidebar

Related Questions

We have a website that uses #include file command to roll info into some
I have website where users can login with their Facebook account. I am using
i have website of application which sells applications online.on the home page i want
I have a website ( http://www.rtistree.com ) which has vertical scrollbar on some pages.
I'm using win7. and i have website which i want to test it with
I have website that will both post to a user's Facebook wall, and allow
What if I have website with a button. User clicks on the button and
Ok i have website, and want to change Leave Reply string near the bottom
i have website with text area where user pastes text which looks like this:
I have a Sitecore site where I want to have website visitor accounts stored

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.