close
Kaspersky Endpoint Security

Welcome to

Kaspersky Endpoint Security


By Kaspersky Endpoint Security


Kaspersky Reset-Testversion 4.0.0.22 Finale ML



Während auf meinem Armaturenbrett Projekt arbeiten, wollte ich anonymen Ergebnismenge von dynamischen SQL im JSON-Format, um zurückzukehren, um es zu konsumieren mit visuellen Widgets.

Die Lösung war eine Datatable zurück und serialisiert es Json.NET verwenden.

Controller Aktion

C # Privat AdventureWorksDB db = new AdventureWorksDB (); public JsonDotNetResult Index (String-Tabelle, string [] Spalten) {     // Ex: localhost / home / index table = Sales.Currency & Spalten = name, currency     Datatable dt = new Datatable ();     var conn = (SqlConnection) db.Database.Connection;     Connectioninitial = conn.State;     if (initial! = ConnectionState.Open)         conn.Open (); // Offene Verbindung, wenn nicht bereits geöffnet     mit (DbCommand cmd = conn.CreateCommand ())     {         cmd.CommandText = String.Format ( "SELECT {0} von {1}", string.Join ( ",", Spalten), Tabelle);         var Leser = cmd.ExecuteReader ();         dt.Load (Leser);     }     return new JsonDotNetResult (dt); } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 Privat AdventureWorksDB db = new AdventureWorksDB (); public JsonDotNetResult Index (String-Tabelle, string [] Spalten) {// ex: localhost / home / index table = Sales.Currency & Spalten = name, currencyDatatable dt = new Datatable (); var conn = (SqlConnection) db. Datenbank. Anschluss; Connectioninitial = Anschl. Bundesland ; if (initial! = Connection. Open) Anschl. Open (); // Offene Verbindung, wenn schon nicht öffnen mit (DbCommand cmd = Anschl. Create ()) {cmd. Commandtext = String. Format ( "SELECT {0} von {1}", string Join ( ",", Spalten), Tabelle.); var reader = cmd. ExecuteReader (); dt. Load (Leser); } Return new JsonDotNetResult (dt); }

Json.NET Aktion Ergebnis

C # public class JsonDotNetResult: Action {     privates Objekt _obj {get; Set; }     public JsonDotNetResult (object obj)     {         _obj = obj;     }     public override void ExecuteResult (Controller Kontext)     {         context.HttpContext.Response.AddHeader ( "Content-Type", "application / json");         context.HttpContext.Response.Write (JsonConvert.SerializeObject (_obj));     } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 public class JsonDotNetResult: Action {private Objekt _obj {get; gesetzt; } Public JsonDotNetResult (object obj) {_obj = obj; } Public override void ExecuteResult (Controller Kontext) {Kontext. Httpcontext. Antwort. AddHeader ( "Content-Type", "application / json"); Kontext. Httpcontext. Antwort. Write (JsonConvert SerializeObject (_obj).); }}

Kaspersky Endpoint Security 2014     Endpoint-Security 2016

Categories and tags