-1
public Dataset getdata(Dataset table) 
{ 
   string JSONString = string.Empty;  
   JSONString = JSONConvert.SerializeObject(table);  
   return JSONString;  
} 

The above code returning string value but signature is dataset please suggest me how to return string value when signature is dataset.

Jim Hewitt
  • 1,726
  • 4
  • 24
  • 26
  • you should just return `table` and save us the stress or follow this: http://stackoverflow.com/questions/11981282/convert-json-to-datatable – Oluwafemi Aug 26 '16 at 11:40

1 Answers1

0

Change the signature to a string:

public string getdata(Dataset table) {

C# is statically typed. The return type advertised by the method is the type which must be returned. If your method returns a string, then use string as the return type. The compiler doesn't like methods which lie about what they return.

David
  • 208,112
  • 36
  • 198
  • 279
  • but i need to return json data formate to dataset is it possible? – veeresh asp Aug 26 '16 at 11:23
  • @veereshasp: In what possible? In the question you're returning a string, so the return type must be `string`. It doesn't matter what that string contains, as long as it's a string. What exactly are you trying to do and what isn't working? – David Aug 26 '16 at 11:24
  • actually i have data in dataset i want to convert it into json formate but i dont want to change signature. – veeresh asp Aug 26 '16 at 11:26
  • @veereshasp: Then return the dataset and convert it to JSON elsewhere in the code. The method either returns a `DataSet` or it returns a `string`. Wanting to change the return type without wanting to change the return type makes no sense. – David Aug 26 '16 at 11:27