In my opinion Cerebrus' approach (using DataView) is best.
But I can't find the 'Add()' method in DataTable Class. Also Following
things should be noted:
1) 'dr.ItemArray' will return the array of Values in each column of
'dr'
2) If a DataRow which is already added in a DataTable canNOT be added
in some other DataTable, using its Reference. One should create a copy
of that DataRow (using ItemArray or some other method) and Add that
copy in other DataTable.
On Nov 12, 4:56 pm, Cerebrus <[EMAIL PROTECTED]> wrote:
> I would rather do it this way :
>
> ---
> DataTable dt = ds.Tables["TBL_MFQueryResult"];
> DataView dv = dt.DefaultView;
>
> // Filter the view according the value in the MF_TYPE column.
> // You only require the single quotes if the column is a char Sql
> Type.
> dv.RowFilter = "MF_TYPE = '0'";
> DataTable dtRenewal = dv.ToTable("Renewal");
>
> // Filter the view according the value in the MF_TYPE column.
> dv.RowFilter = "MF_TYPE = '1'";
> DataTable dtNewActive = dv.ToTable("New Active");
>
> ---
>
> If you must do it your way, you already have the reference to the
> required DataRow in your For-Each block, so why do you need to
> reference it from the DataTable ?
>
> ---
> dsRenewal.Tables[0].Add(dr.ItemArray);
> ---
>
> On Nov 12, 2:45 pm, Benj Nunez <[EMAIL PROTECTED]> wrote:
>
>
>
> > Hello experts,
>
> > Currently I'm stuck in a situation in which I need to copy a record
> > from one dataset
> > to another. Can anyone help me out with this?
>
> > My goal is to loop through a dataset and check if a certain field
> > meets a criterion,
> > if there's a match, that record goes through another dataset. Here's
> > what my code looks like:
>
> > DataSet dsRenewal = new DataSet();
> > DataSet dsNewActive = new DataSet();
> > ...
>
> > foreach (DataRow dr in ds.Tables["TBL_MFQueryResult"].Rows)
> > {
> > if (dr["MF_TYPE"] == '0') // '0' means its a renewal, '1'
> > New Active and so on...
> > {
> > dsRenewal.Tables[0].Add(ds.Tables["TBL_MFQueryResult"].Rows
> > [?].ItemArray); // huh?
> > }
> > else if (dr[...])
> > {
> > dsNewActive.Tables[]....
> > }
> > ...
>
> > }
>
> > Cheers!
>
> > Benj- Hide quoted text -
>
> - Show quoted text -