开发者

How can i add the row dynamically at an exact postion in a dataset

I write a code to add dynamical column and row to a data set but the field is added some where in my data-set so can any one te开发者_开发技巧ll how can I resolve this

My code

for (int i = 0; i < AchDB.Amount1.Count; i++)
    {
        DataColumn dc = new DataColumn("Amount1");
        local_ds.Tables[0].Columns.Add(dc);
        local_ds.Tables[0].Rows.Add(AchDB.Amount1[i]);
    }

I need as per in the image shown

How can i add the row dynamically at an exact postion in a dataset


Maybe you can use this:

DataColumn dc = new DataColumn("Amount1");
local_ds.Tables[0].Columns.Add(dc);

for (int i = 0; i < AchDB.Amount1.Count; i++)
{
    local_ds.Tables[0].Rows[i]["Amount1"] = AchDB.Amount1[i];
}

I did put the code for adding a new column outside the loop. I think adding the column once will be applicable for all rows.


You can use the "InsertAt" method of DataTable for inserting the row at specific position. For the columns there is no direct way of adding a column at a specific position. When you add a column to a datatable - it always gets added at the last.

dt.Rows.InsertAt(newRowObject,pos);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜