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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:47:58+00:00 2026-06-17T21:47:58+00:00

I am trying to query data of a specific column text from another column.

  • 0

I am trying to query data of a specific column text from another column.

Basically, I have a Supplier Database that has a SupplierID and Country column.

I already have the SupplierID for that specific row for example, it is 14. I would like to get the text value of Country column based on the 14 value.

The Supplier ID I am getting by the following code (listbox):

<asp:ListBox ID="SupplierListBox" runat="server" 
            DataSourceID="SupplierCompanyDataSource" DataTextField="Company" 
            DataValueField="SupplierID" Width="315px" 
            Height="80px" 
            onselectedindexchanged="SupplierListBox_SelectedIndexChanged" 
            AutoPostBack="True"></asp:ListBox>

Code:

        string SupplierListvalue = SupplierListBox.SelectedItem.Value; //SupplierListvalue retrieves the SupplierID value

        SqlDataReader rdr = null;
        SqlConnection conn = new SqlConnection("Data Source=localhost;Initial Catalog=ROG;Integrated Security=True");
        SqlCommand cmd = new SqlCommand("select Country from SupplierDB", conn);
        cmd.Connection = conn;

        conn.Open();
        rdr = cmd.ExecuteReader();
        while (rdr.Read())
        {
            TextBox1.Text = rdr["Country"].ToString();
            MessageBox.Show("Connection Successful");
            MessageBox.Show(rdr.ToString());
        }

        conn.Close();
  • 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-17T21:47:59+00:00Added an answer on June 17, 2026 at 9:47 pm

    Well, it’s not clear what’s the main problem, so i’ll show you a working example which selects the Country column from database with ADO.NET, uses Parameters to avoid SQL-Injection and using-statement to ensure that all unmanaged resources as the connection get disposed(closed).

    string sql = @"
                SELECT Country
                FROM dbo.Supplier
                WHERE SupplierID = @SupplierId";
    using (var con = new SqlConnection("Data Source=localhost;Initial Catalog=ROG;Integrated Security=True"))
    {
        using (var cmd = new SqlCommand(sql, con))
        {
            con.Open();
            cmd.Parameters.Add("@SupplierId", SqlDbType.Int);
            cmd.Parameters["@SupplierId"].Value = int.Parse(SupplierListBox.SelectedItem.Value);
            using (var rdr = cmd.ExecuteReader())
            {
                if (rdr.Read())
                {
                    TextBox1.Text = rdr.GetString(0);
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was trying to select pretty specific data from the database but my query
I am trying to graph data that I am pulling from an ActiveRecord query
I am retrieving data from a database and trying to populate a List<>. That
I'm trying to get records from a table that have a language column. If
I'm trying to query a table with a column which is xml data with
I am trying to do a simple AJAX function to send data from query
I am trying to get my data from a query string, but use it
I'm trying to make a little app that displays only images from a specific
I'm trying to generate XML from database and need to gather a specific amount
I need to created a query in MS Access 2010 that combines data 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.