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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:48:07+00:00 2026-05-25T19:48:07+00:00

I’m having trouble creating a table and putting data pulled from SQL into it.

  • 0

I’m having trouble creating a table and putting data pulled from SQL into it. My solution at the moment is to create a table in Default.aspx, and then create the rows and cells in the C# code.

My aspx code:

<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <h2>
        Select a topic to view.
    </h2>
    <asp:Table ID="solutions" runat="server" Width="100%">
    </asp:Table>
</asp:Content>

And where all the action should, but doesn’t happen:
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HtmlAgilityPack;
using System.Data.SqlClient;

namespace WebApplication1
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            SqlConnection anca = new System.Data.SqlClient.SqlConnection();
            anca.ConnectionString = "Data Source=anca;Initial Catalog=servicedesk;
            anca.Open();

            SqlCommand sub = new SqlCommand("SELECT TITLE FROM dbo.Solution", anca);
            SqlDataReader sReader = sub.ExecuteReader();
            List<String> subject = new List<string>();
            int solCount = 0;
            while (sReader.Read())
            {
                subject.Add(sReader.ToString());
                solCount++;
            }
            sReader.Close();

            TableRow newRow = new TableRow();
            TableCell newcell = new TableCell();

            int adder = 0;
            while (adder <= solCount)
            {
                solutions.Rows.Add(newRow);
                for (int i = 0; i <= 6; i++)
                {
                    newRow.Cells.Add(newcell);
                    newcell.Text = subject[adder].ToString();
                }
            }
        }
    }
}

Obviously I’m a bit green with it all. Basically what happens is it pulls all of the solution titles from a database and I want the titles to each be in a cell of their own, where I will go on to link them to the respective pages. Hopefully it all makes sense, if not I am happy to provide more information.

  • 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-25T19:48:07+00:00Added an answer on May 25, 2026 at 7:48 pm

    First you are adding empty row to table and then filling the row with content. You should add the row after its filled with cell content (i.e. after the loop not before). Also if I am not seeing it wrong, you are not increasing “adder” each loop so it should fall into infinite loop. Also seems like you are pulling only title from DB…so I don’t know why you were trying to add 7 columns/cells each row. By the way posting this from office so let me know if I did anything wrong and I will fix it asap :).

    while (adder < solCount)
                {
                    var cell = new TableCell();
                    var row = new TableRow();
    
                    cell.Text = subject[adder].ToString();
                    row.Cells.Add(newcell);
                    solutions.Rows.Add(newRow);
                    ++adder;
                }
    

    I think a more elegant way will be using ListView or Repeater control rather than dynamically generating the table like that.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have some data like this: 1 2 3 4 5 9 2 6

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.