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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:40:02+00:00 2026-06-02T02:40:02+00:00

RESOLVED.. This has been resolved as I was making a stupid mistake. I didn’t

  • 0

RESOLVED..

This has been resolved as I was making a stupid mistake. I didn’t initialize the string builder
StringBuilder sb = new StringBuilder();

I am using the following CTE query in my website to fetch data using c#. But it is giving an error in the if Statement inside for loop

ERROR MESSAGE

System.NullReferenceException was unhandled by user code
Message=Object reference not set to an instance of an object.

    String strSqlCTE;

    strSqlCTE= " DECLARE @PageId int ";
    strSqlCTE += " SET @PageId =" + pageid + "; ";
    strSqlCTE += " WITH RecursiveTable (PageId, PageName, PageInternalLink, PageInternalLinkUrl, PageInheritance, Level) ";
    strSqlCTE += " AS(SELECT      tt.PageId,  tt.PageName, tt.PageInternalLink, tt.PageInternalLinkUrl, tt.PageInheritance,  0 AS Level ";
    strSqlCTE += " FROM pg_Pages AS tt WHERE PageId = @PageId ";
    strSqlCTE += " UNION ALL ";
    strSqlCTE += " SELECT tt.PageId,  tt.PageName, tt.PageInternalLink, tt.PageInternalLinkUrl, tt.PageInheritance, Level + 1 ";
    strSqlCTE += " FROM pg_Pages AS tt ";
    strSqlCTE += " INNER JOIN RecursiveTable rt ON rt.PageInheritance = tt.PageId  ) ";
    strSqlCTE += " SELECT * FROM RecursiveTable ORDER BY Level DESC ";

    DataSet dsBC = new DataSet();
    dsBC = DataProvider.Connect_Select(strSqlCTE);
    if (dsBC.Tables[0].Rows.Count > 0)
    {
        int RowCount = dsBC.Tables[0].Rows.Count;
        StringBuilder sb = null;
        for ( int i = 0; i <= RowCount; i++)
        {
            if (i == RowCount)
            {
                sb.Append("<a href='" + dsBC.Tables[0].Rows[0]["PageInternalLinkUrl"].ToString() + "'>" + dsBC.Tables[0].Rows[0]["PageName"].ToString().ToUpper() + "</a>");
            }
            else
            {
                sb.Append("<a href='" + dsBC.Tables[0].Rows[0]["PageInternalLinkUrl"].ToString() + "'></a> ● ");
            }

        }

        ltrBreadCrumb.Text = sb.ToString();

    }

My CTE query is is working and below is the actual query

DECLARE @PageId int
SET @PageId = 31;
WITH RecursiveTable (PageId, PageName, PageInternalLink, PageInternalLinkUrl, PageInheritance, Level)
AS(
   --Anchor
    SELECT      tt.PageId,  tt.PageName, tt.PageInternalLink, tt.PageInternalLinkUrl, tt.PageInheritance,  0 AS Level
    FROM pg_Pages AS tt
    WHERE PageId = @PageId
    UNION ALL
   --Recursion
    SELECT tt.PageId,  tt.PageName , tt.PageInternalLink, tt.PageInternalLinkUrl, tt.PageInheritance, Level + 1
    FROM pg_Pages AS tt
    INNER JOIN RecursiveTable rt ON rt.PageInheritance = tt.PageId
)
SELECT * FROM RecursiveTable ORDER BY Level DESC

This works good on when run in the Management studio but following statement generate error

sb.Append("<a href='" + dsBC.Tables[0].Rows[0]["PageInternalLinkUrl"].ToString() + "'></a> ● ");

dsBC.Tables[0].Rows.Count statement return correct row numbers based on the input. Problems seems to be in the as it cant recognize column name which is present in the CTE query.

Am I am doing something wrong please correct me about the problem.

  • 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-02T02:40:04+00:00Added an answer on June 2, 2026 at 2:40 am

    This has been resolved as I was making a stupid mistake. I missed to initialize string builder

    StringBuilder sb = new StringBuilder();
    
    String strSqlCTE;
    
        strSqlCTE= " DECLARE @PageId int ";
        strSqlCTE += " SET @PageId =" + pageid + "; ";
        strSqlCTE += " WITH RecursiveTable (PageId, PageName, PageInternalLink, PageInternalLinkUrl, PageInheritance, Level) ";
        strSqlCTE += " AS(SELECT      tt.PageId,  tt.PageName, tt.PageInternalLink, tt.PageInternalLinkUrl, tt.PageInheritance,  0 AS Level ";
        strSqlCTE += " FROM pg_Pages AS tt WHERE PageId = @PageId ";
        strSqlCTE += " UNION ALL ";
        strSqlCTE += " SELECT tt.PageId,  tt.PageName, tt.PageInternalLink, tt.PageInternalLinkUrl, tt.PageInheritance, Level + 1 ";
        strSqlCTE += " FROM pg_Pages AS tt ";
        strSqlCTE += " INNER JOIN RecursiveTable rt ON rt.PageInheritance = tt.PageId  ) ";
        strSqlCTE += " SELECT * FROM RecursiveTable ORDER BY Level DESC ";
    
        DataSet dsBC = new DataSet();
        dsBC = DataProvider.Connect_Select(strSqlCTE);
        if (dsBC.Tables[0].Rows.Count > 0)
        {
            int RowCount = dsBC.Tables[0].Rows.Count;
            StringBuilder sb = new StringBuilder();
            for ( int i = 0; i <= RowCount; i++)
            {
                if (i == RowCount)
                {
                    sb.Append("<a href='" + dsBC.Tables[0].Rows[i]["PageInternalLinkUrl"].ToString() + "'>" + dsBC.Tables[0].Rows[i]["PageName"].ToString().ToUpper() + "</a>");
                }
                else
                {
                    sb.Append("<a href='" + dsBC.Tables[0].Rows[i]["PageInternalLinkUrl"].ToString() + "'></a> ● ");
                }
    
            }
    
            ltrBreadCrumb.Text = sb.ToString();
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

UPDATE 2011.09.13 This bug has been resolved by Adobe. The example code below now
Since I posted this question, this issue has resolved itself. There must have been
EDIT: Sorry Guys, This has been resolved The comment to check the inline style
[This question has been resolved in the chat room, by Spacedman , but I'm
I have asked this question ever before and it seems I didn't 100% resolved
I apologize in advance if folks think this has been beaten to death. I've
Follow up question to a previous question , this has been identified as a
I have a project with Spring, JSF and Hibernate. This project has been developed
Edit 4: The main issue has been resolved - turned out the problem was
Has anyone used JustCode from Telerik lately? This question has been asked about two

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.