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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:12:28+00:00 2026-06-01T03:12:28+00:00

I am Using Visual Studio 2008. I am trying to print all the data

  • 0

I am Using Visual Studio 2008.
I am trying to print all the data from a table in html formatted table
I am getting only the first row from Database printed but I want all the data to be printed on the screen.
See the code I have written.
Please help me out.

 public void cj()
{
    connString = "Data Source=CJ-PC;Initial Catalog=Electro;Integrated Security=True";
    using(con = new SqlConnection(connString))
    {
        con.Open();
        string sqlQuery = "Select * from CUSTOMER_DETAIL";
        using(cmd = new SqlCommand(sqlQuery,con))
        {
            using (sdr = cmd.ExecuteReader())
            {
                using (DataTable dt = new DataTable())
                {
                    dt.Load(sdr);
                    PlaceHolder1.Controls.Add(new LiteralControl("<table style='border:solid 2px Red; width:600px;'>"));
                    PlaceHolder1.Controls.Add(new LiteralControl("<tr>"));
                    int i = 0;
                    foreach (DataColumn dc in dt.Columns)
                    {
                        i++;
                        Label myLabel = new Label();
                        myLabel.ID = Convert.ToString(i);                            
                        PlaceHolder1.Controls.Add(new LiteralControl("<td style='border:solid 2px Blue;'>"));
                        myLabel.Text = "" + dc.ToString();
                        PlaceHolder1.Controls.Add(myLabel);
                        PlaceHolder1.Controls.Add(new LiteralControl("</td>"));
                    }
                    PlaceHolder1.Controls.Add(new LiteralControl("</tr>"));

                    PlaceHolder1.Controls.Add(new LiteralControl("<tr>"));
                    int j = 0;
                    foreach (DataRow dr in dt.Rows)
                    {                           
                        if(j < dt.Columns.Count)
                        {
                            Label myLabel = new Label();
                            myLabel.ID = Convert.ToString(i);
                            PlaceHolder1.Controls.Add(new LiteralControl("<td style='border:solid 2px aqua;'>"));
                            myLabel.Text = "" + dr[j].ToString();
                            PlaceHolder1.Controls.Add(myLabel);
                            PlaceHolder1.Controls.Add(new LiteralControl("</td>"));
                        }
                        j++;
                    }
                    PlaceHolder1.Controls.Add(new LiteralControl("</tr>"));
                    PlaceHolder1.Controls.Add(new LiteralControl("</table>"));
                }                           
            }
        }
  • 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-01T03:12:29+00:00Added an answer on June 1, 2026 at 3:12 am

    problem is in your code when bind columns each of the row

    you should add do while for append columns of the rows.
    this function should be work according to your logic :

          foreach (DataRow dr in dt.Rows)
                    {
                        PlaceHolder1.Controls.Add(new LiteralControl("<tr>"));      
                         int k = 0;
                         do
                          {
                            Label myLabel1 = new Label();
                            myLabel1.ID = Convert.ToString(k);
                            PlaceHolder1.Controls.Add(new LiteralControl("<td style='border:solid 2px aqua;'>"));
                            myLabel1.Text = "" + dr[k].ToString();
                            PlaceHolder1.Controls.Add(myLabel1);
                            PlaceHolder1.Controls.Add(new LiteralControl("</td>"));
                            k++;
                          } while (k < dt.Columns.Count);
                         PlaceHolder1.Controls.Add(new LiteralControl("</tr>"));    
                    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to print a datagridview by drawing to bitmap using visual studio 2008
We are developing a multilingual Winforms application using visual studio 2008. I am trying
I am trying to build the Intellesoft BugTrap source using Visual Studio 2008. I
I'm trying to start a new ASP.NET Web Application Project using Visual Studio 2008.
using Visual.Web.Developer.2010.Express; using SQL.Server.Management.Studio.2008.R2; What I'm ultimately trying to do is update a sql
I'm using Visual Studio 2008 SP1 and trying to debug a website created in
I'm using Visual Studio 2008 trying to debug a C# project. I had some
I'm using Visual Studio 2008 with the October 2009 F# CTP installed. I'm trying
I am trying to make an Outlook 2003 add-in using Visual Studio 2008 on
I'm trying to install my Windows Service app using Visual Studio 2008 Setup and

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.