0

I want to get a nested json file like,

{
    "table": "table_name",
    "mode": "read",
    "data": [{
            "code": "123",
            "name": "name1",
            "place": "place_name1"
        }, {
            "code": "456",
            "name": "name2",
            "place": "place_name2"
        }, {
            "code": "789",
            "name": "name2",
            "place": "place_name2"
        }
    ]
}

I tried to retrieve one entire datatable to the datarow of another datatable.:( Seeking your help..

3
  • 2
    show some code. Commented Dec 26, 2018 at 7:19
  • 1
    Possible duplicate of Create nested json with c# Commented Dec 26, 2018 at 7:20
  • dr["table"] = tableName.ToString(); dr["mode"] = "read"; dr["data"] = dtItemMaster.ToString(); dtInfo.Rows.Add(dr); ... This is what i tried Commented Dec 26, 2018 at 7:48

1 Answer 1

0

Suppose you have to table table1 and table2 and Objdb is your database Entities and both table have an relation like id or anything then you can do that like this

var ss = objdb.Table1.Where(x => x.Table1Id >= 0).ToList();
var tblList = ss.Select(x => new
{
tbl2 = objdb.Table2
  .Where(z => z.Table1Id == x.Table1Id)
   .Select(s => new
          {
           code= s.code,
           name= s.name,
           place= z.place
          }).ToList()
}).ToList();
Sign up to request clarification or add additional context in comments.

2 Comments

No relation between two table, one is database table and another is manually created. i want to add the datatable from database into the other.
i have given you idea how you can do that now you must try your data table logic what you are trying to do and i think then there must be any common column or condition you can use that or try to update your question so that i we can help you better thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.