如何将一个表的多列行添加到另一个表中? [英] how to add one's tables multiple columns rows into another table?

查看:91
本文介绍了如何将一个表的多列行添加到另一个表中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有GridView,其中包含两列。我想将GridView数据添加到另一个表中意味着将一个表多个列和行数据放入另一个表的单行中。我正在尝试这个对我无效的查询因为我也有这些变量

I have GridView which include Two columns. I want to add GridView data into another Table means one tables multiple columns and rows data into another tables's single row. I am trying this query which is not valid for me becuase i have these variable also

objProduct.Tax1Name
objProduct.Tax1Rate
objProduct.Tax2Name
objProduct.Tax2Rate
objProduct.Tax3Name
objProduct.Tax3Rate
objProduct.Tax4Name
objProduct.Tax4Rate
objProduct.Tax5Name
objProduct.Tax5Rate



所有这些都需要包含在这个foreach循环中,这对我来说是不可能的。


and all this need to include in this foreach loop which is not possible for me.

foreach (DataGridViewRow daRw in gvTaxingScheme.Rows)
{
   objProduct.Tax1Name= daRw.Cells["ColumnTaxName"].Value.ToString();
   objProduct.Tax1Rate = Convert.ToDecimal(daRw.Cells["ColumnTaxRate"].Value);
} 



如何将一个表的多列行添加到另一个表中?


how to add one's tables multiple columns rows into another table??

推荐答案

我的建议是你用一个全局列表填充你的Grid,可以随时出于任何原因访问你。



这样你就有了列表的强大功能每次你去服务器时都可用,内存成本很低。



基本上只需填充你的gridview数据源:



My suggestion is that you populate your Grid with a global list that can be accessed any time for any reason you want.

This way you will have the power of a list available everytime you go to the server, at a low cost of memory.

basically, just populate your gridview datasource like this:

List< MyCustomObject> list = new List< MyCustomObject>();

public void PopulateGrid()
{
list.Clear();

list.Add(new MyCustomObject() { ... });
...


grid.DataSource = list;
grid.DataBind();

}













.
.
.

public class MyCustomObject
{
    public int ID { get;set; }
    [...]
}


这篇关于如何将一个表的多列行添加到另一个表中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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