Solved

DataTable in Json format

Posted on 2012-03-09
2
1,406 Views
Last Modified: 2012-03-10
Hello,

I am using Visual Studio 2010, Visual C#, .NET framework 4.0.

I have app in IIS. All my methods looks something like this:


        [OperationContract]
        [WebGet(ResponseFormat = WebMessageFormat.Json)]
        public string Select()
        {            
            return "Hello World";
        }

And the work fine - the only problem is how to return DataTable in Json format?

I've found this topic: http://schotime.net/blog/index.php/2008/07/27/dataset-datatable-to-json/

But, nothings comes back from the server. The dictionary<string, object> is created, but nothing is returned from server.

I need to return DataTable in Json format and the (on the client) convert this back to DataTable and show in DataGrid (Windows forms).


Regards, Frenky
0
Comment
Question by:AntonioRodrigo
2 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 37705022
Frankly, Frenky, I would use a business object, instead of a DataTable.  You can apply a DataContract to the class, and DataMember to the members, and return a list of those objects.
0
 

Author Closing Comment

by:AntonioRodrigo
ID: 37705639
Yes, very good point. And that list of object I can map to DataTable on the client. I've also found one solution by myself: put DataTable into MemoryStream and return MemoryStream.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now