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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:46:08+00:00 2026-06-17T00:46:08+00:00

In my C# Web Application I have simple page where a user enters their

  • 0

In my C# Web Application I have simple page where a user enters their first name in one textbox (named txtFirst) and their last name in another textbox (named txtLast). After they enter this information in the two textboxes, they click on a continue button which saves the data to a SQL database. My problem is trying to save these values in SQL. I have a “Value” table (columns are PersonID, AttributeID, and Value) and an “Attribute” table (columns are a primary key AttributeID and AttributeName).

In my Attribute table I have the following:

AttributeID:   AttributeName: 
    1            FirstName 
    2            LastName

My goal is to have this save in the Value table as:

PersonID:       AttributeID:             Value: 
    A                1                     FirstName Value Here
    B                2                     LastName Value Here

I know how to save the data by directly passing it into a stored procedure, but how can I have the AttributeID get assigned correctly? (Example: AttributeID = 1 for FirstName and AttributeID = 2 for LastName). Is there a way I can assign the textboxes in the application to have a specific AttributeID or even by AttributeName? Thanks so much.

It might be confusing, but the idea here is for when the button is clicked, it pulls the AttributeID associated to FirstName from the table and then saves the value and that pulled AttributeID in table “Value”. Thanks

  • 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-17T00:46:09+00:00Added an answer on June 17, 2026 at 12:46 am

    I would store them in the ViewState or Session depending on what you are doing:

    //Code to get the values from the database.
    Session("FirstNamePersionId") = fnamePId;
    Session("FirstNameAttributeId") = fnameAId;
    Session("LastNamePersionId") = lnamePId;
    Session("LastNamePersionId") = lnameAId;
    //other code.
    

    Then to access just use Session("FirstNamePersionId") or what ever you called the value.

    I would wrap the calls to the ViewState or Session in properties to make it easier to maintain and read.

    Let me know if you need an example.

    Update:
    To get the values from the database you can try the following.

    int fNameId = -1, lNameId = -1;
    SqlConnection sqlConn = new SqlConnection(conString);//conString is the connection string for your DB.  This should be the same as what you use to execute the stored procedure.
    SqlCommand sqlQuery = new SqlCommand("SELECT AttributeID, AttributeName FROM Attribute WHERE AttributeName IN ('FirstName','LastName')", sqlConn);
    SqlDataReader sqlReader;
    
    sqlConn.Open();
    sqlReader = sqlQuery.ExecuteReader();
    if (sqlReader.HasRows)
    {
        while (sqlReader.Read())
        {
            if (sqlReader[1].ToString().Equals("FirstName", StringComparison.CurrentCultureIgnoreCase))
            {
                fNameId = (int)fNameId;
            }
            else if (sqlReader[1].ToString().Equals("LastName", StringComparison.CurrentCultureIgnoreCase))
            {
                lNameId = (int)fNameId;
            }
        }
    }
    sqlReader.Close();
    sqlConn.Close();
    

    If you want you can make a separate call for each id, but that adds a bit of processing overhead. If you do make two calls then I suggest using the same SqlConnection, though you will need to create a new command.
    Accessing the results by id (as I did using sqlReader[1]) is sometimes frowned upon. I personally do not worry about it since I declare the column order in the SQL query.
    This would probably be easier using LINQ2SQL.
    Let me know if I made any mistakes or missed anything.

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

Sidebar

Related Questions

I have a simple web application which lets the user upload local user data
I'm currently working on a simple web application where users each have their own
In my web application, I have users input a date in a simple textbox.
I have a simple web browser embedded in an application that allows a user
I have a simple page in a PHP/MySQL web application that lets admin users
I have an MVC 3 web application project, and in one page I use
I have a seam web application and for one page I have an hardcoded
I have written a simple web Application which is running(on Tomcat Server) fine on
We have a very simple ASP.NET web application comprising mostly static content and a
I have an extremely simple web application running in Tomcat using Spring 3.0.2, Hibernate

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.