如何将数据列表选择的项目添加到数据库?

问题描述:

hi如何将数据列表中选定的项目添加到数据库中.
例如,如果我单击添加按钮时从数据库中选择了一行,则该行应存储到数据库中.如何为此提供代码.可以提供任何帮助吗?

hi how to add datalist selected items to database..

for example if i selecte one row from database when i click to add button it should stored to database..how to give code for that..??can any one help??

例如,基本上是工作流(直接使用SqlClient对象时):
-创建SqlConnection
-创建SqlCommand
-使用SqlParameters为命令设置正确的SQL INSERT语句
-定义参数的值
-执行命令
-放置物体

正确完成后,它将包裹在try..catch块中,并使用SqlTransaction,尤其是例如在循环执行命令(插入多行等)的情况下.
Basically the workflow goes for example (when using SqlClient objects directly):
- Create a SqlConnection
- Create a SqlCommand
- set the proper SQL INSERT statement for the command using SqlParameters
- define the values for the parameters
- execute the command
- dispose the objects

And when done properly it''s wrapped inside a try..catch block and a SqlTransaction is used especially if you for example execute the command in loop (insert multiple rows etc.)