ich eine SQL-Tabelle mit Werten haben wie:Problem beim Konvertieren Datentabelle, um verschachtelte json C#
Main_group Sub_group CstCmpCode
COMBO SET DD-101 AH01
COMBO SET DD-102 AH01
ich verschachtelte JSON-String erstellen müssen wie:
{
"CstCmpCode": "AH01",
"Main_Group": "COMBO SET",
"sub_group": [
{
"Sub_Group": "DD-101",
},
{
"Sub_Group": "DD-102",
}
]
}
Mein Code wie unten für die Umwandlung von Datentabelle zu verschachtelten json string:
System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["TallyWeb"].ToString());
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "select distinct Main_group, Sub_group, CstCmpCode from TlyStkSumm where CstCmpCode = @CstCmpCode";
cmd.Parameters.AddWithValue("@CstCmpCode", CstCmpCode);
DataSet ds = new DataSet();
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.SelectCommand.Connection = con;
da.Fill(dt);
con.Close();
List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();
Dictionary<string, object> row = null;
foreach (DataRow rs in dt.Rows)
{
row = new Dictionary<string, object>();
foreach (DataColumn col in dt.Columns)
{
row.Add(col.ColumnName, rs[col]);
}
rows.Add(row);
}
Pls. überprüfe das oben was ich falsch mache.
Danke.
Yogesh.Sharma
Welche Ausgabe erhalten Sie derzeit? Daten? ein Fehler? –
Ich erhalte einen Fehler: "Fehler beim Konvertieren von Wert \" \ u0004 Primär \ "zum Eingeben von \ u0027System.Collections.Generic.List'1 [WebService + Untergruppe] \ u0027. Pfad \ u0027 [0] .Sub_Gruppe \ u0027, Zeile 1 , Position 48. " –
irgendein pls. Hilf mir ?? –