[英]Repitition of a query in sql server from C#.NET Winform application
i want to run the same query ten times. 我想运行相同的查询十次。
INSERT INTO items VALUES ('item_name')
GO 10
i can use GO , but i want to do this from my .net winform application. 我可以使用GO,但是我想从我的.net winform应用程序中执行此操作。 when the user clicks a button then the query gets executed and inserts 10 rows into the table ITEMS.
当用户单击按钮时,查询将被执行并将10行插入表ITEMS中。 whats the solution for this ?
有什么解决方案呢?
You need to do this in your C# code: 您需要在C#代码中执行此操作:
for(int i = 1; i <= 10; i++)
{
cmdInsert.ExecuteNonQuery();
}
The GO
is not a valid SQL keyword - it's a SQL Server Management Studio addition that works only in SSMS (and btw: you can rename that to anything you like in the SSMS options dialog - try renaming it to SELECT
and have some fun :-) ) GO
不是有效的SQL关键字-这是仅在SSMS中有效的SQL Server Management Studio附加功能(顺便说一句:您可以在SSMS选项对话框中将其重命名为任意名称-尝试将其重命名为SELECT
并获得一些乐趣:- ))
您可以循环到插入命令
In straight SQL: 在直接SQL中:
DECLARE @I INT
SET @I = 0
WHILE (@I < 10)
BEGIN
INSERT INTO items VALUES ('item_name')
SET @I = @I + 1
END
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.