Click here to Skip to main content
15,900,589 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
can i insert array into database without using loop
i have a checkbox list containing project_id so i have insert that record in a table
for each project a new row

i am inserting subadmin for multiple project so i am keeping those records in a table
like
SQL
adminid  projectid
1         1
1         2
1         3
2         4
2         5
3         6
3         7
3         8
3         9
3         10


through checkbox list i m fetching projectid and store it in an array for particular admin
so without using loop(for insert query) can i insert these records in DB
Posted
Updated 31-Jan-13 1:08am
v4
Comments
Sergey Alexandrovich Kryukov 31-Jan-13 3:11am    
The question does not make a lot of sense. It all depends on what is modeled by this array and corresponding part of database schema, how you want it in the database and other detail. Use "Improve question", above.
—SA

Rather depends how you are accessing the db.
Your options are:

Send a table parameter to a stored procedure
Concatenation the data into a comma separated string and have a loop in ther SQL
Build the SQL command in your client (using a loop) so it can send one SQL command to do the entire update.

I'm guessing one of these would suit your requirements, but would need more information to help further.
 
Share this answer
 
Comments
Miss Maheshwari 31-Jan-13 4:04am    
have a loop in ther SQL

can u tell me how to make a loop in sql...
i never did that
Well you must to iterate. If you are philosophically contrary to loops then you may try with a recursive approach (good luck).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900