Created
June 11, 2018 09:55
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Data; | |
using System.Linq; | |
using System.Threading.Tasks; | |
using Microsoft.AspNetCore.Mvc; | |
using Newtonsoft.Json.Linq; | |
namespace MyProject.Controllers | |
{ | |
public class MainController : Controller | |
{ | |
private string DataTableToJson(DataTable dt) | |
{ | |
if (dt == null) | |
{ | |
return "[]"; | |
}; | |
if (dt.Rows.Count < 1) | |
{ | |
return "[]"; | |
}; | |
JArray array = new JArray(); | |
foreach (DataRow dr in dt.Rows) | |
{ | |
JObject item = new JObject(); | |
foreach (DataColumn col in dt.Columns) | |
{ | |
item.Add(col.ColumnName, dr[col.ColumnName]?.ToString()); | |
} | |
array.Add(item); | |
} | |
return array.ToString(Newtonsoft.Json.Formatting.Indented); | |
} | |
public string GetData(string Key,string Data) | |
{ | |
return DataTableToJson(Helpers.DBHelper.ExecuteQuery("SELECT * FROM INBOX")); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment