我想在不使用数据库的情况下将datagridview数据复制到数据集. [英] I want to copy datagridview data to dataset without using a database.

查看:77
本文介绍了我想在不使用数据库的情况下将datagridview数据复制到数据集.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我想在不使用数据库的情况下将datagridview 数据复制到dataset .我想写一堂课.

请帮我解决这个问题.
:confused :: confused :: confused :: confused :: rose:

我只想复制数据...

.
.
.
请帮助我...

hi all,

I want to copy datagridview data to dataset without using a database. I want to write a class.

Please help me to solve this problem .
:confused::confused::confused::confused::rose:

I want to copy data only...

.
.
.
Please help me...

推荐答案

无法猜出为什么需要一个类来做同样的事情!仍然是这里...

您可以这样获得:

Couldn''t guess out why you need a class to do the same! Still, here it is...

You can get like this:

//If DataSource of GridView1 is a DataTable
DataTable dt = (DataTable)GridView1.DataSource;
//Now add this table to DataSet



如果要在移植数据时进行一些更改,则必须遍历.您必须先手动创建列,然后遍历所有行.



If you want to make some changes while porting the data, you have to loop through. You have to manually create columns first, then loop through all the rows.

//This is just a Psuedocode
DataTable dt = new DataTable();
//Add columns here
dt.Columns.Add(); //or something similar
//go on till all the columns are added
//loop and second loop
foreach(GridViewRow gvr in GridView1.Rows)
{
   DataRow dr = dt.NewRow();
   
   //second loop - looping all columns
   for(int i = 0; i < gvr.Rows.Count; ++i)
   {
      dr[i] = gvr.Cells[i].Text;
   }
}
//Add datatable to Dataset as you want here



现在,如果需要,您可以将这段代码放在一个类中并公开它.在需要时调用它.



Now if you want, you can put this piece of code in a class and expose it. Call it when you need to.


这篇关于我想在不使用数据库的情况下将datagridview数据复制到数据集.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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