在C#.net的datagridview中插入数据 [英] Insert data in datagridview in c#.net

查看:115
本文介绍了在C#.net的datagridview中插入数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

先生
我想一次在Sql Server 2008 r2中插入多个记录.

Sir
I want to insert multiple record at a time in Sql server 2008 r2.

推荐答案

选项之一是使用AddNewDataSource 向导创建Strongly Typed DataSet VisualStudio.该向导在MS SQL Server中生成与Tables 相对应的DataSetDataTables.它还为每个Table创建TableAdapter ,以填充数据并将DataTable 的所有行更新为MS SQL Server中的相应Table .

在此说明连接到Data
在Visual Studio概述中连接到数据 [数据源配置向导 [用于从DataBase和使用反射将DataTable保存到数据库中 [如何:使用设计器将数据绑定到Windows Forms DataGridView控件 [ ^ ]

我认为这可能会有所帮助.
One of the options is to create a Strongly Typed DataSet using the AddNewDataSource wizard of VisualStudio. This wizard generates the DataSet and DataTables corresponding to the Tables in the MS SQL Server. It also creates TableAdapter for each of the Table for filling the data and updating all the rows of the DataTable to the corresponding Table in MS SQL Server.

Connecting to Data is explained here
Connecting to Data in Visual Studio Overview [^]
Data Source Configuration Wizard[^]

One problem with this approach is that for filling the data into the DataTable and saving the data from the DataTable to the database the TableAdapter corresponding to the DataTable is to be used as the DataTables and TableAdapters are strongly typed.

However, using reflection a common class can be written to handle the filling and saving data for all or some DataTables. Such class is given in this CodeProject article
General purpose class to fill DataTable(s) from DataBase and to save DataTable(s) to DataBase using reflection[^]

Binding the data to DataGridView is explained here
How to: Bind Data to the Windows Forms DataGridView Control Using the Designer [^]

I think it may be helpful.


这篇关于在C#.net的datagridview中插入数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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