插入数组没有循环 [英] insert array without loop

查看:85
本文介绍了插入数组没有循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在不使用循环的情况下将数组插入数据库吗

i有一个包含project_id的复选框列表所以我在表中插入了该记录
每个项目的
新行



i我为多个项目插入subadmin所以我将这些记录保存在表格中



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

adminid  projectid
1         1
1         2
1         3
2         4
2         5
3         6
3         7
3         8
3         9
3         10





通过复选框列表即时取件projectid并将其存储在特定管理员的数组中

所以不使用循环(用于插入查询)我可以在DB中插入这些记录



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

推荐答案

取决于你如何访问数据库。

您的选择是:



将表参数发送到存储过程

将数据串联成逗号分隔的字符串,并在SQL中有一个循环

在客户端构建SQL命令(使用循环),这样它就可以发送一个SQL命令来完成整个更新。



我猜其中一个符合您的要求,但需要更多信息来帮助您。
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.


嗯,必须进行迭代。如果你在哲学上与循环相反,那么你可以尝试使用递归方法(祝你好运)。
Well you must to iterate. If you are philosophically contrary to loops then you may try with a recursive approach (good luck).


这篇关于插入数组没有循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆