2

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. when the user clicks a button then the query gets executed and inserts 10 rows into the table ITEMS. whats the solution for this ?

3 Answers 3

4

You need to do this in your C# code:

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 :-) )

Sign up to request clarification or add additional context in comments.

2 Comments

sir , when GO can't be used from C# application, then in real applications , is there any use of it? like developers do use it, if yes, then where?
@sqlchild: "GO" is used in SSMS - and only there.
1

You can loop to your insert command

Comments

1

In straight SQL:

DECLARE @I INT

SET @I = 0

WHILE (@I < 10)
BEGIN
   INSERT INTO items VALUES ('item_name')
   SET @I = @I + 1
END

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.