如何在jqgid中使用存储过程?

时间:2015-06-15 09:03:48

标签: sql asp.net-mvc-4 stored-procedures jqgrid

我想使用存储过程来填充我的JqGrid。我的存储过程如下:

ALTER  PROCEDURE [dbo].[SubJqGridObisDataSP]
as begin
DECLARE @header AS NVARCHAR(MAX),@MetID AS bigint 
SELECT @header = 
STUFF((SELECT ',' + QUOTENAME([ObisInfoTranslateT]) 

     from MetContDB.dbo.tblMet AS met
     join MetContDB.dbo.tblMod AS mod on mod.ModID= met.ModID_FK  
     join MetContDB.dbo.tblGroupData As Gro on Gro.MetID_FK= met.MetID
     join MetContDB.dbo.tblObisData as obisdata on     obisdata.GroupDataID_FK=Gro.GroupDataID
     join MetContDB.dbo.tblObisInfo AS obisinfo on obisinfo.ObisInfoID=obisdata.ObisInfoID_FK
     join (select  max(GroupDataID) as maxgroupdata   from MetContDB.dbo.tblGroupData   where MetID_FK=@MetID) g on Gro.GroupDataID=g.maxgroupdata 
     where met.MetID=@MetID

        FOR XML PATH(''), TYPE
        ).value('.', 'NVARCHAR(MAX)') 
    ,1,1,'')
DECLARE @DynamicPIVOT AS NVARCHAR(MAX) 
SELECT @DynamicPIVOT = 'SELECT ' + @header +
' FROM (
select 
obisdata.ObisData,
       obisinfo.[ObisInfoTranslateT]

      from MetContDB.dbo.tblMet AS met
     join MetContDB.dbo.tblMod AS mod on mod.ModID= met.ModID_FK  
     join MeterControlDB.dbo.tblGroupData As Gro on Gro.MetID_FK= met.MetID
     join MetContDB.dbo.tblObisData as obisdata on obisdata.GroupDataID_FK=Gro.GroupDataID
     join MetContDB.dbo.tblObisInfo AS obisinfo on obisinfo.ObisInfoID=obisdata.ObisInfoID_FK
     join(select 
           max(GroupDataID) as maxgroupdata
           from MeterControlDB.dbo.tblGroupData
        where MetID_FK=@MetID) g on Gro.GroupDataID=g.maxgroupdata 
        where met.MetID=@MetID) Books
PIVOT (MAX(ObisData) FOR [ObisInfoTranslateT] IN (' + @header + ')) Result;'

EXEC (@DynamicPIVOT)
end

但是当我在我的控制器中使用这个SP时,我得到错误:存储过程的输出是int ????? 我的输出存储过程是某一行。控制器:

MetContDBEntities ctnx = new MetContDBEntities();
var obisDatas = ctnx.SubJqGridObisDataSP(id).ToList();

查询之前的代码是:

select obisdata.ObisData,obisinfo.ObisInfoTranslateT
      from MetContDB.dbo.tblMet AS met
     join MetContDB.dbo.tblMod AS mod on mod.ModID= met.ModID_FK  
     join MetContDB.dbo.tblGroupData As Gro on Gro.MetID_FK= met.MetID
     join MetContDB.dbo.tblObisData as obisdata on obisdata.GroupDataID_FK=Gro.GroupDataID
     join MetContDB.dbo.tblObisInfo AS obisinfo on obisinfo.ObisInfoID=obisdata.ObisInfoID_FK
     join(select 
           max(GroupDataID) as maxgroupdata
           from MetContDB.dbo.tblGroupData
        where MetID_FK=39) g on Gro.GroupDataID=g.maxgroupdata 
        where met.MetID=39

输出: enter image description here 我想这样表现: enter image description here

通过第一次查询,我可以将pic1更改为pic2。

0 个答案:

没有答案