shashi
shashi

Reputation: 4696

Create object at runtime based on SqlQuery executed

The overall objective is to get a Json representation of the query results of the SqlQuery executed. This Json will be used to create visualizations/reports on the browser using js based charting tools.

Now, controls like gridview are able to read the column names as well as the data and give us an html representation of the data. So I think it should be possible to write code such that it can read from a sql data reader and come up with a json representation.

I could not find anything in my searches which does what I want. How do I go about doing this? any pointers?

Upvotes: 1

Views: 326

Answers (2)

sanosdole
sanosdole

Reputation: 2489

You could use the Json.Net serializer. It supports serializing a Dictionary<string,object> to a JSON object. Another big shot would be using NHibernate and serializing the resulting objects.

Here is another link to using the Json.Net serializer for DataSets:

If you scroll down to the comments on this page you see a much shorter solution using the Dictionary approach.

Upvotes: 0

Roy Goode
Roy Goode

Reputation: 2990

You could use an SqlDataAdapter to fill a DataSet. This blog post describes a way of converting a DataTable or DataSet into its JSON representation.

Upvotes: 1

Related Questions