Sometimes it's more convenient to use a string rather a dataset. So if you handle a dataset, you must convert it to string. The best way to do that is to convert it to json string.
And then, after you finish everything, you'll need to convert that string back to dataset so that you can save the result into the database or display it.
In this entry I'll show you the easiest way to do that using
Json.NET
In this project I use .NET 2.0. If you want to use .NET 3.5 all you have to do is remove reference Newtonsoft.Json.Net20 and add the Newtonsoft.Json.Net35 in bin folder.
Dataset to Json String
StringWriter sw = new StringWriter();
ds.WriteXml(sw, XmlWriteMode.IgnoreSchema);
XmlDocument xd = new XmlDocument();
xd.LoadXml(sw.ToString());
string jsonText = JsonConvert.SerializeXmlNode(xd);
txtResult.Text = jsonText;
First, if you want to convert DataSet to Json String you have to convert DataSet to XMLDocument (Here I use StringWritter).
When you've already added Newtonsoft.Json.Net to you References, you can use JsonConvert to convert between JSON and XML. If you want to convert o JSON String, use SerializeXmlNode. This method takes an XmlNode and serializes it to JSON text.