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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:23:50+00:00 2026-06-07T15:23:50+00:00

I would like to retrieve a particular column from a table when the values

  • 0

I would like to retrieve a particular column from a table when the values from two other columns are equal. My code is as follows. The four columns are id,destination,source,price.

I want to display the price when the destination and source are equal.

Could you please help me?

private void button1_Click(object sender, EventArgs e)
{

        SqlConnection con = new SqlConnection("Data source=.;initial catalog=loki;integrated security=true");
        con.Open();
        SqlDataAdapter da = new SqlDataAdapter();

        DataTable dt = new DataTable();
        da.SelectCommand = new SqlCommand("select  price from metro where source='" + textBox1.Text + "' and destination='" + textBox2.Text + "'", con);
        da.Fill(dt);
        for(int i=0;i<dt.Rows.Count;i++)
        {
            textBox3.Text = dt.Rows[0][3].Count.ToString();
        }
    }
  • 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-07T15:23:52+00:00Added an answer on June 7, 2026 at 3:23 pm

    I thing you are after this ….

        private void button1_Click(object sender, EventArgs e)
        {
            using (SqlConnection con = new SqlConnection("Data source=.;initial catalog=loki;integrated security=true"))
            {
                string query = "select  price from metro where source= @Source and destination = @Destination";
    
                using (SqlCommand cmd = new SqlCommand(query, con))
                {
                    cmd.Parameters.AddWithValue("@Source", textBox1.Text);
                    cmd.Parameters.AddWithValue("@Destination", textBox2.Text);
    
                    con.Open();
                    object o  = cmd.ExecuteScalar();
                    if(o != null && o != DBNull.Value)
                    {
                       string price = (string) o; //please cast the return type as required
                       textBox3.Text = price;
                    }
                    con.Close();
                }
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to retrieve particular data from a txt file and would like
I would like to retrieve the AppSetting key from the assembly config file called:
Would like to know the c# code to actually retrieve the IP type: Static
I would like to retrieve the contents of a file, filter and modify them
I would like to retrieve an ordered query result, but I need to have
I would like to retrieve the categories of my website in order to build
I am saving images to the photo library and would like to retrieve them
I have a set of URLs for which I would like to retrieve the
I'm using the python suds module and would like to retrieve the response headers
I am adding data to my database, but would like to retrieve the UnitID

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.