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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:12:14+00:00 2026-06-18T06:12:14+00:00

How can i execute a SELECT query from my Code Behind file and then

  • 0

How can i execute a SELECT query from my Code Behind file and then iterate through it?

I want to do something like this (just a simple pseudo example):

// SQL Server
var results = executeQuery("SELECT title, name FROM table");

foreach (var row in results)
{
    string title = row.title;
    string name = row.name;
}

How can i do this within code?

  • 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-18T06:12:15+00:00Added an answer on June 18, 2026 at 6:12 am

    Something like this:

     string queryString = 
        "SELECT OrderID, CustomerID FROM dbo.Orders;";
    using (SqlConnection connection = new SqlConnection(
               connectionString))
    {
        SqlCommand command = new SqlCommand(
            queryString, connection);
        connection.Open();
        SqlDataReader reader = command.ExecuteReader();
        try
        {
            while (reader.Read())
            {
                Console.WriteLine(String.Format("{0}, {1}",
                    reader["OrderID"], reader["CustomerID"]));
            }
        }
    }
    

    Source: http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.aspx

    The connectionString will vary depending on the Database product and the authentication mechanism used (Windows Auth, username/password, etc.). The example above assumes you are using SQL Server. For a complete list of different ConnectionStrings, go to http://www.connectionstrings.com/

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

Sidebar

Related Questions

I have a query in my Ruby file: @mastertest = connection.execute(select code_ver, date from
When I execute a sql statement like Select ..., I can only see ...100%
Question: Want to perform a Select Query below (must be this query): SELECT QuestionId
I'm execute a simple mssql query from python. I can see in the profiler
I execute a scripted query from a .sql file with SqlCommand. I get the
Can anyone tell me how I can execute my custom jQuery code when Drupal's
I wonder if I can execute some programs for different cmd's using .bat file.
For my database I create a new query and wrote select * from dbname
I can compile but can't execute the following code with the error (using Postgres):
I can't show the data from database sqlite in python. connection = sqlite3.connect('db') connection.cursor().execute('CREATE

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.