从datagrid插入到SQL表值C# [英] Insert from datagrid to SQL table values C#
本文介绍了从datagrid插入到SQL表值C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从datagrid插入到sql表值c#
我在数据网格中有一些datagrid和inserti。 ..
数据网格没有sql表
我需要插入从数据网格到SQL表..
一些rocamndition?
我尝试了什么:
我在代码中从文本框和组合框中插入了clasic插入到datagrid
解决方案
很少有观察
- 在循环外建立连接
- 在循环外准备命令
- 在循环外创建参数
- 在语句中定义目标列
- 在循环内部重用参数,只需在其中设置新值
- 使用try..catch
- 并在整个操作中使用交易,以便插入所有内容或不插入任何内容。
更多详情所有这些都包含在正确执行数据库操作 [Insert from datagrid to sql table values c#
I have some datagrid and inserti into that datagrid...
That datagrid no have sql table
I need to insert into values from That datagrid to SQL table..
Some rocamndition?
What I have tried:
I have clasic insert into code from textboxes and comboboxes to datagrid解决方案Few observations
- Establish the connection outside the loop
- Prepare the command outside the loop
- Create the parameters outside the loop
- Define the target columns in the statement
- Inside the loop reuse the parameters, just set new values into them
- Utilize try..catch
- And use a transaction for the whole operation so that everything is inserted or nothing.
For more details, all of these are covered in Properly executing database operations[^]
这篇关于从datagrid插入到SQL表值C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文