2010-11-03 74 views
0

在我的應用程序中,我想要使用動態列diaply使用存儲過程。使用linq動態結果存儲過程調用的問題

我該如何做到這一點???

USE [ASIF] 
GO 
/****** Object: StoredProcedure [dbo].[USP_GET_TABLE] Script Date: 11/03/2010 15:45:30 ******/ 
SET ANSI_NULLS ON 
GO 
SET QUOTED_IDENTIFIER ON 
GO 
ALTER PROCEDURE [dbo].[USP_GET_TABLE] 
@TABLENAME VARCHAR(100), 
@SELECT VARCHAR(100) 
AS 
BEGIN 
DECLARE @pQUERY NVARCHAR(MAX) 
SET @pQUERY = 'SELECT '+ @SELECT +' FROM '+ @TABLENAME 

EXEC SP_EXECUTESQL @pQUERY 
END 

回答

0

整蠱!在Linq to SQL的情況下。試試這個:

 string tableName = "TABLENAME"; 

     switch(tableName) 
     { 
      case "Table1": 
       Table1Type abc = yourEntityContext.ExecuteQuery(Table1Type, "exec USP_GET_TABLE", new object[] { "TABLENAME", "SELECT param" }); 
       break; 

     }