1
votes

I have one dataset in which there are 2 tables available.This tables are filled from databse while loading the page. Now consider my scenario. When Page loads,this two tables of dataset are filled with data from database.

Table 1 : Project Master with 1 rows(Master table)
Table 2 : Project Detail with 5 rows(Child table - bound in GridView)

If i do nothing to "Project Detail" table, then i value of MyDataset.Tables["ProjectDetailTable"].GetChanges(DataRowState.Modified) is NULL.

But if i add the new Data Row into "Project Detail" table from UI, the i will get value of MyDataset.Tables[TableName].GetChanges(DataRowState.Modified) is the datatable with added new row.

In UI, I want to sort the "Project Detail" table when user adds the new Data Row from UI.So i did code like this and created method when new datarow is added.

private void SortProjectDetailTable(ref DataSet ds)
{
    DataView dv = new DataView(ds.Tables["ProjectDetailTable"]);
    DataTable dtTemp = new DataTable("ProjectDetailTable");
    dv.Sort = " DATE DESC ";
    dtTemp = dv.ToTable().Copy();

    if (ds.Tables.Contains("ProjectDetailTable"))
        ds.Tables.Remove("ProjectDetailTable");

    ds.Tables.Add(dtTemp);
}

This method sorts the datatable perfectly. But when i try to get the value of "MyDataset.Tables["ProjectDetailTable"].GetChanges(DataRowState.Modified)", I get it NULL while value of "MyDataset.Tables["ProjectDetailTable"].GetChanges(DataRowState.Added)" is DataTable with 6 Rows.

Actually I want it like this

  • MyDataset.Tables["ProjectDetailTable"].GetChanges(DataRowState.Modified) value should be "1 New Added Row from UI"
  • MyDataset.Tables["ProjectDetailTable"].GetChanges(DataRowState.Added) value should be "NULL" because i get 5 rows from databse in page load event

Finally, Problem is that I want to sort the Datatable in Dataset without affecting Original state of rows in Dataset.

1

1 Answers

0
votes
you can use another dataset for new rows for UI and then sort it
after copy it in your dataset