使用LIST到存储过程INSERT [英] INSERT using LIST into Stored Procedure
本文介绍了使用LIST到存储过程INSERT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个存储过程:
CREATE PROCEDURE [RSLinxMonitoring].[InsertFeatures]
@Features nvarchar(50),
@TotalLicenses int,
@LicensesUsed int,
@ServerName nvarchar(50)
AS
SET NOCOUNT ON
INSERT INTO [RSLinxMonitoring].[FeatureServer]
([Features]
,[TotalLicenses]
,[LicensesUsed]
,[Server])
VALUES(@Features
,@TotalLicenses
,@LicensesUsed
,@ServerName)
它工作正常,但因为我需要插入退出从我的C#LINQ到SQL类了一下,我想从我的应用程序中插入一个列表,而不是,这可能吗?
It works as expected, but since I need to insert quit a bit from my C# Linq-to-SQL class, I would like to insert a list from my application instead, is this possible?
我已经看到它已经完成然后用 SELECT
语句,但不使用时, INSERT
结果
更新:
由于LINQ to SQL的不支持用户自定义表类型我不能表。 (
I have seen it been done then using SELECT
statement, but not when using INSERT
.
UPDATE:
Since LINQ to SQL Doesn't support User-Defined Table Types i can't Tables. :(
推荐答案
如果您正在使用SQL Server 2008和放大器;上面,你可以使用下面的解决方案
申报表。键入如下:
If you are using SQL server 2008 & above, you can use below solution. Declare Table type like :
CREATE TYPE FeatureServerType AS TABLE
(
[Features] nvarchar(50)
,[TotalLicenses] int
,[LicensesUsed] int
,[Server] nvarchar(50)
);
使用它像:
CREATE PROCEDURE [RSLinxMonitoring].[InsertFeatures]
@TabletypeFeatures FeatureServerType READONLY
AS
SET NOCOUNT ON;
INSERT INTO [RSLinxMonitoring].[FeatureServer]
([Features]
,[TotalLicenses]
,[LicensesUsed]
,[Server])
SELECT * FROM @TabletypeFeatures
这篇关于使用LIST到存储过程INSERT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文