Sunday 15 July 2012

Creating a new DataResultSet from an Existing DataResultSet

Most of us would have come across the scenario in which you need to create new DataResultSet object with the same fields as that of an existing DataTesultSet.

Following is the steps to create a DataResultSet from an existing DataResultSet without creating fields one by one.

1) Create a DataResultSet Object
 DataResultSet finalResultSet = new DataResultSet();   

2) Merge the fields from the source DataResultSet object
  finalResultSet.mergeFields(coverPageResult);

3) Add an empty row
  finalResultSet.createEmptyRow();

4) Get the field values from the source
                for(int x=0;x<rowList.size();x++) 
{
                    selectedList = new Vector();                   
         selectedList = coverPageResult.getRowValues(Integer.parseInt(rowList.get(x).toString()));
                    finalResultSet.addRow(selectedList)
       }

           Note : This step is to copy a subset of rows from the source dataresultset object to target. Based on your requirements, this step may vary.  Also creating a Vector/List object to add the values into the row is easier than adding values one by one especially if you want to copy them from one dataresultset object to another.
 

No comments:

Post a Comment