如何将数据列表选择的项目添加到数据库? [英] how to add datalist selected item to database?

查看:207
本文介绍了如何将数据列表选择的项目添加到数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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.)


这篇关于如何将数据列表选择的项目添加到数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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