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 插入存储过程


- 在 LINQ to SQL 中使用 contains() 2022-01-01
- C# 通过连接字符串检索正确的 DbConnection 对象 2022-01-01
- 在 C# 中异步处理项目队列 2022-01-01
- 为什么 C# 中的堆栈大小正好是 1 MB? 2022-01-01
- CanBeNull和ReSharper-将其用于异步任务? 2022-01-01
- 是否可以在 .Net 3.5 中进行通用控件? 2022-01-01
- 使用 rss + c# 2022-01-01
- 带问号的 nvarchar 列结果 2022-01-01
- Azure Active Directory 与 MVC,客户端和资源标识同一 2022-01-01
- Windows 喜欢在 LINUX 中使用 MONO 进行服务开发? 2022-01-01