且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将列表传递到数据库?

更新时间:2023-02-10 12:58:16

您不应在循环中添加参数(因为它们是在每次迭代中添加的,这会在第二次迭代中引起麻烦). br/>
相反,您应该在循环之前定义参数,并在循环中为它们分配一个值.
You should not add parameters in the loop (because they are added at each iteration, which will cause trouble at the second iteration).

Instead, you should define the parameters before the loop, and assign them a value in the loop.


我?我会将列表转换为DataTable,然后直接通过DataAdapter传递.
这可能会有所帮助:将列表转换为数据表 [ ^ ]
Me? I''d convert the list to a DataTable and pass that directly via a DataAdapter.
This might help: Converting a List to a DataTable[^]


您可以尝试使用实体框架连接数据库,这在进行列表操作时非常容易.
查看 https://msdn.microsoft.com/en-us/library /aa697427(v=vs.80).aspx
you can try entity framework to connect the database, it is far easy when doing list operation.
check out https://msdn.microsoft.com/en-us/library/aa697427(v=vs.80).aspx