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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:07:43+00:00 2026-06-09T11:07:43+00:00

Recently I was working on a project in which JSON was used, I had

  • 0

Recently I was working on a project in which JSON was used, I had two approaches to get data from database to facilitate my JavaScript with Json string,

First

Is to do processing in database to form a Json string, like this

select   
       ID,
    '{ "Comments": ['+
    Substring(
        (SELECT 
           ',{ '+
           '"Comment" : "' + REPLACE(Comments,'"','\"') + '",'+
           '"Name" : "' + REPLACE(Name,'"','\"') +
         '}'
    FROM    JsonTbl
    where   JsonTbl.ID = tbl.ID
    for xml path('')
    ),2,250000)
      +'] }' as JsonData
from tbl

Second

Is to select data from database without any processing and do processing of creating a Json string in front end, like this

DataTable data = GetDataFromDatabase();
StringBuilder sb = new StringBuilder();
sb.Append("{ \"Comments\": [");
for (int i = 0; i < data.Rows.Count; i++)
{
    sb.Append("{");
    sb.Append("\"Comment\" : \"" + data.Rows[i]["Comment"].ToString().Replace('"', '\"') + "\",");
    sb.Append("\"Name\" : \"" + data.Rows[i]["Comment"].ToString().Replace('"', '\"') + "\"");
    sb.Append("},");
}
sb.Remove(sb.Length - 1, 1);

I was wondering which one would be better from performance as well as maintenance point of view.

NOTE : Please consider that I’ve trimmed the code to post here original code is much larger than this, and I’m using MSSQL 2008 and .Net(C#)

  • 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-09T11:07:45+00:00Added an answer on June 9, 2026 at 11:07 am

    A better approach would be to get your data through SQL Server, create an object based on that data in C# and use JSON serializers for JSON. May be JSON.Net. You may face problems with maintaining your code with your current approaches.

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

Sidebar

Related Questions

Recently, i am working with jquery for my mini-project. I took a code from
I've recently moved a project I'm working on from .NET 3.5 to .NET 4.
Recently I am working with project a in which i want the value of
Recently we started working with Database project in Visual Studio 2010. I have added
Having recently begun working on a project which might need (good) scaling possibilities, I've
I'm recently working on a project in which I need to port a portion
I have been working with a small project recently which involves Struts 2 and
I have recently started working on some open source project which I found relevant
Recently I'm working on project which requires a large no. of object should be
I recently started working on a web project which was already in progress; the

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.