在我的一个应用程序中,我想使用存储过程使用动态列显示。我该如何实现?
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 :(得分: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;
}