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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:17:24+00:00 2026-05-28T22:17:24+00:00

My list returns back <string, string> apparently. How can I append the second string

  • 0

My list returns back <string, string> apparently. How can I append the second string in my KeyValuePair and add in the ID that I get back from my second database call?

    // Database calls here

    KeyValuePair<string, string> parks = new KeyValuePair<string, string>();

    DataSet dset = new DataSet();

    var list = new List<KeyValuePair<string, string>>();

    list.Add(new KeyValuePair<string, string>("Select one", "0"));
    foreach (DataRow row in ds.Tables[0].Rows)
    {
        //My database calls including:
         db.AddInParameter(comm, "@pID", DBType.Int32, row[1]);
         dset = db.ExecuteDataSet(comm);
         string attr = dset.Tables[0].Rows[0]["Value"].ToString();
        list.Add(new KeyValuePair<string, string>(row[0].ToString() + " - " + attr, row[1].ToString()));

    }

    return list;
  • 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-28T22:18:01+00:00Added an answer on May 28, 2026 at 10:18 pm

    in KeyValuePair<TKey, TValue> key and value are readonly. you can use Dictionary<string,string> for you work and get KeyValuePair<string, string> from it.

    I think this works:

    // Database calls here
    Dictionary<string, string> list = new Dictionary<string, string>();
    
    list.Add("Select one", "0");
    foreach (DataRow row in ds.Tables[0].Rows)
    {
    
        list.Add(row[0].ToString(), row[1].ToString());
    
    }
    
    //Another database call that gets back an ID. I want to add/append this ID into my second string in my KeyValue Pair.
    
    return list;
    

    for append the second string you can use list["/*Your ID*/"]= YourData;

    List<KeyValuePair<TKey, TValue>> is not good way. It’s like that you use a cup of tea for offing the fire!

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

Sidebar

Related Questions

I have class method that returns a list of employees that I can iterate
I have a method that returns a list of type string. I want to
I am making a call to a servie that returns a list of jso
I have a basic soap service running on glassfish, that returns List<String> like this
Consider following scenario: I have RESTful URL /articles that returns list of articles user
I want a query that returns a list of all the (user) stored procedures
I have a webservice that returns a list of Clinics near a certain lat/long.
I've got a Fitnesse RowFixture that returns a list of business objects. The object
Why am I getting a textbox that returns undefined list of variables? When I
I have a XML string comming from a Rest WS that I created on

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.