INSERT using LIST into Stored Procedure(使用 LIST 插入存储过程)
问题描述
我有这个存储过程:
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-to-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 插入存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 LIST 插入存储过程


基础教程推荐
- 我什么时候应该使用 GC.SuppressFinalize()? 2022-01-01
- C# - 将浮点数转换为整数...并根据余数更改整数 2022-01-01
- Page.OnAppearing 中的 Xamarin.Forms Page.DisplayAlert 2022-01-01
- 创建属性设置器委托 2022-01-01
- 如何使用OpenXML SDK将Excel转换为CSV? 2022-01-01
- 使用 SED 在 XML 标签之间提取值 2022-01-01
- 当键值未知时反序列化 JSON 2022-01-01
- 覆盖 Json.Net 中的默认原始类型处理 2022-01-01
- C# - 如何列出发布到 ASPX 页面的变量名称和值 2022-01-01
- 从 VB6 迁移到 .NET/.NET Core 的最佳策略或工具 2022-01-01