简体   繁体   English

从C#.NET Winform应用程序重新定位SQL Server中的查询

[英]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.

相关问题 使用SQL Server Express为ac#.net winform应用程序创建多个用户 - creating multiple users for a c#.net winform application using sql server express 如何使用C#.NET Winform从SQL Server Compact数据库检索返回行值 - How to retrieve return row value from a SQL Server Compact database using C#.NET winform 如何从数据库(SQL Server)动态创建MenuStrip(在Winform C#.Net中)? - How to Create MenuStrip dynamic (in winform C#.Net) From Database (SQL Server)? 从C#.Net Winform应用程序中的多个数据源读取 - Reading from multiple data sources in C#.Net Winform Application 代码性能:SQL Server查询与C#.Net Web应用程序 - Code performance: SQL Server Query vs C#.Net web application 将TLS 1.2与C#.Net Winform App和SQL Server 2008一起使用 - Using TLS 1.2 with C#.Net Winform App and SQL Server 2008 后端使用SQL Server 2008的C#.Net应用程序上的TCP错误 - TCP error on a C#.Net application with SQL Server 2008 on the backend 在 C#.NET 应用程序中使用 SQL 服务器时间数据类型? - Use SQL Server time datatype in C#.NET application? 在 WinForm 应用程序中使用 C#.Net 从 USB 条码扫描仪读取一维和二维条码 - Read 1D and 2D Barcode from USB Barcode Scanner using C#.Net in WinForm Application 无法从C#.net应用程序连接到oracle服务器 - cannot connect to oracle server from C#.net application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM