在C#.net的datagridview中插入数据 [英] Insert data in datagridview in c#.net
本文介绍了在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
相对应的DataSet
和DataTables
.它还为每个Table
创建TableAdapter
,以填充数据并将DataTable
的所有行更新为MS SQL Server
中的相应Table
.
在此说明连接到Data
在Visual Studio概述中连接到数据 [数据源配置向导 [用于从DataBase和使用反射将DataTable保存到数据库中 [如何:使用设计器将数据绑定到Windows Forms DataGridView控件 [ ^ ]
我认为这可能会有所帮助.
One of the options is to create aStrongly Typed DataSet
using theAddNewDataSource
wizard ofVisualStudio
. This wizard generates theDataSet
andDataTables
corresponding to theTables
in theMS SQL Server
. It also createsTableAdapter
for each of theTable
for filling the data and updating all the rows of theDataTable
to the correspondingTable
inMS SQL Server
.
Connecting toData
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 theDataTable
and saving the data from theDataTable
to the database theTableAdapter
corresponding to theDataTable
is to be used as theDataTables
andTableAdapters
are strongly typed.
However, usingreflection
a common class can be written to handle the filling and saving data for all or someDataTables
. 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 toDataGridView
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屋!
查看全文