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

  • Home
  • SEARCH
  • 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 3307346
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:23:44+00:00 2026-05-17T21:23:44+00:00

I would like to pull data from my server and add to a table

  • 0

I would like to pull data from my server and add to a table object. Loop thru the data afterwhich I would like to display the results on the aspx page.

DataTable dTable = new DataTable();
dTable.Columns.Add("idNum", typeof(Int64));
dTable.Columns.Add("Name", typeof(String));
dTable.Columns.Add("Age", typeof(Int64));
//Connection/Command/Statement
DataReader dr = command.ExecuteReader();
while (dr.Read()) { /*Add data to rows*/ }

How do I add the data to the rows? What is the best way to display on aspx?

  • 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-17T21:23:45+00:00Added an answer on May 17, 2026 at 9:23 pm

    Try this code, I tested on my local:

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.IsPostBack)
            return;
    
        BindDG();
    }
    
    private void BindDG()
    {
    
        SqlConnection connection = new SqlConnection("Data Source=servername;Initial Catalog=dbname;Integrated Security=True");
        using (connection)
        {
            SqlCommand command = new SqlCommand("select * From staff;",connection);
            connection.Open();
    
            SqlDataReader reader = command.ExecuteReader();
    
            if (reader.HasRows)
            {
                DataTable dt = new DataTable();
                dt.Columns.Add("ID", typeof(int));
                dt.Columns.Add("Name", typeof(string));
                dt.Columns.Add("Age", typeof(int));
    
                while (reader.Read())
                {
                    int id = (int)reader["id"];
                    string name = reader["name"].ToString();
                    int age = (int)reader["age"];
    
                    dt.Rows.Add(id, name, age);
                }
    
                GridView1.DataSource = dt;
                GridView1.DataBind();
            }
            else
            {
                Reponse.Write("No records found.");
            }
            reader.Close();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Linq/EF4.1 to pull some results from a database and would like to
The aim: I would like a Tumblr blog to pull CSS from a Rails
I'm using C# to pull spatial data from a sql server 2008 database. I'm
I need to pull data for a report from a SQL Server 2008 R2
I have an app that needs to pull data from a server and insert
I am running a php website and would like to pull in the most
On my page I have a section where I would like to pull in
We have a bunch of user controls we would like to pull out of
I have an IEnumerable<DateTime> . I would like to pull out all dates that
I would like jQuery to pull the url, then parse it to find airports.

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.