如何返回两个Json
对象?基本上我正在尝试从 sql db 发送一堆数据和 db 中的行数。
下面的代码发送myData
成功,但现在我也想发送count
.
string sqlquery = "SELECT Q1, Q2, Q3, Q4, Improvements, Comments FROM myTable";
conn.Open();
SqlDataAdapter cmd = new SqlDataAdapter(sqlquery, conn);
SqlCommand comd = new SqlCommand(sqlquery, conn);
DataSet myData = new DataSet();
cmd.Fill(myData, "myTable");
comd.CommandText = "SELECT COUNT(*) FROM myTable";
Int32 count = (Int32)comd.ExecuteScalar();
comd.ExecuteNonQuery();
conn.Close();
return JsonConvert.SerializeObject(myData, Formatting.Indented,
new JsonSerializerSettings
{
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
});
这是我的网格
this.grid = Ext.create('Ext.grid.Panel', {
title: 'GridView App',
frame: true,
trackMouseOver: true,
disableSelection: true,
autoHeight: true,
store: store,
loadMask: true,
columns: [
{ header: 'Q1',
sortable: true, dataIndex: 'Q1'
},
{ header: 'Q2',
sortable: true, dataIndex: 'Q2'
},
{ header: 'Q3',
sortable: true, dataIndex: 'Q3'
},
{ header: 'Q4',
sortable: true, dataIndex: 'Q4'
},
{ header: 'Improvements', flex: 1,
sortable: true, dataIndex: 'Improvements'
},
{ header: 'Comments', flex: 1,
sortable: true, dataIndex: 'Comments'
}
],
这是我的商店...
var store = Ext.create('Ext.data.JsonStore', {
storeId: 'myData',
scope: this,
pagesize: itemsPerPage,
remoteSort: true,
fields: [
{ name: 'Q1', type: 'int' },
{ name: 'Q2', type: 'int' },
{ name: 'Q3', type: 'int' },
{ name: 'Q4', type: 'int' },
{ name: 'Q5', type: 'int' },
{ name: 'Improvements', type: 'string' },
{ name: 'Comments', type: 'string' }
],
sorters: [
{
property: 'Q1',
direct: 'ASC'
}
],
proxy: {
type: 'ajax',
scope: this,
url: 'GridView/writeRecord',
reader: {
type: 'json',
root: 'myTable',
totalProperty: 'count'
}
}
});