inserting multiple rows

Dear experts
 iam using .net(c#) and sql server 2000 , i want to insert 65 rows at a time in a table i.e., these all are check boxes all are stored a table if a client select all the 65 rows, i want to insert like this

AID          Supplierid
1                   1
2                   1
3                   1............

like this i want to insert 65 rows, now iam inserting each row using loop , its take too much time and sometimes it showing time expired, please help me
ninusajilAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Pratima PharandeCommented:
you xan try this

INSERT INTO MyTable  (FirstCol, SecondCol)
SELECT  'First' ,1
UNION ALL
SELECT  'Second' ,2
UNION ALL
SELECT  'Third' ,3
UNION ALL
SELECT  'Fourth' ,4
UNION ALL
SELECT  'Fifth' ,5

http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RubenvdLindenCommented:
I would recommend to use the loop to create an SQL-statement as mentioned by pratima_mcs and then execute it.
This will save you the time of writing the long SQL-statement.
StringBuilder sb = new StringBuilder();
sb.AppendLine ("INSERT INTO MyTable (AID, Supplierid)");
 
for (int i = 1; i <= 35; i++)
{
    sb.AppendLine("SELECT " + i + ", 1");
 
    if (i != 35)
       sb.AppendLine("UNION ALL");
}

Open in new window

0
RubenvdLindenCommented:
Sorry, my previous code example will only loop to 35. I have now included the correct code for an SQL-statement which inserts 65 lines.
StringBuilder sb = new StringBuilder();
sb.AppendLine ("INSERT INTO MyTable (AID, Supplierid)");
 
for (int i = 1; i <= 65; i++)
{
    sb.AppendLine("SELECT " + i + ", 1");
 
    if (i != 65)
       sb.AppendLine("UNION ALL");
}

Open in new window

0
Anthony PerkinsCommented:
If you are interested I can post a solution using Xml and a single INSERT statement.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.