c# - DataTable select help -
i trying convert datatable list. please me query?
var result = datatable1.asenumerable().select(e => {e.field<int>("mid"), e.field<string>("mtx")}).tolist(); javascriptserializer ser = new javascriptserializer(); string json = ser.serialize(result);
thank you..
you need provide names properties inside select
call. these names not automatically , unambiguously resolve in particular case. try
var result = datatable1.asenumerable().select(row => new { mid = row.field<int>("mid"), mtx = row.field<string>("mtx") }); javascriptserializer serializer = new javascriptserializer(); string json = serializer.serialize(result);
those names become part of json result. such
[{"mid":1,"mtx":"a"},{"mid":2,"mtx":"b"}]
Comments
Post a Comment