开发者

How to add particular number of rows to a datatable in C# .net?

I have 'n' number of rows in datatable1. Now i want add 'n' number of rows to datatable2.Its notable that two datatables are having different number o开发者_如何转开发f columns.Can anyone please help me with c# coding?

I have used following code but it doesn't work.

            datatable1 = feeCompBLL.getcommunity();
            foreach (DataRow drow in datatable1.Rows)
            {
                DataRow table2rows = datatable2.NewRow();
                datatable2.Rows.Add(table2rows );

            }


You, can use datatable2 = datatable1.Copy(); to do ur work. Hope it helps.


if the two datatables are having different number of columns you should specify the particular colum that you are trying to insert into the "datatable2"

eg

foreach (DataRow drow in datatable1.Rows)
{
  DataRow table2rows = datatable2.NewRow();                
  table2rows[columname] = drow[columnname];
  datatable2.Rows.Add(table2rows);            
}

that is you will have to assign the correct column name or column number to the new row.


To help you I need some info on the code; 1. does datatable2 have columns defined 2. What is FeeSetupRow

If columns are added already, I fee, datatable2.Rows.Add(FeeSetupRow) should be like datatable2.Rows.Add(table2rows).

If you want to copy also the data from datatable1 to datatable2 then you follow as kalyan specified.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜