views:

476

answers:

1

I have a dataset which is having some 28 columns Now I want to make another dataSet that will contain two dataTable having 14 columns in each table from the previous dataset.

Help needed.

+1  A: 

I will asumme you have some data in it.

Create to Datatables one with the first 14 columns(firstPart), and the other with the lasts 14 columns plus the primary key(secondPart).

    DataTable firstPart = new DataTable();
    //Initialize columns here...

    DataTable secondPart = new DataTable();
    //Initialize columns here...

    foreach(DataRow r in original.Rows){
        DataRow f = firstPart.NewRow();
        f[0] = r[0];
        f[1] = r[1];
        f[2] = r[2];
        f[3] = r[3];
        f[4] = r[4];
        f[5] = r[5];
        f[6] = r[6];
        f[7] = r[7];
        f[8] = r[8];
        f[9] = r[9];
        f[10] = r[10];
        f[11] = r[11];
        f[12] = r[12];
        f[13] = r[13];
        firtPart.Rows.Add(f);

        DataRow s = secondPart.NewRow();
        s[0] = r[0];
        s[1] = r[14];
        s[2] = r[15];
        s[3] = r[16];
        s[4] = r[17];
        s[5] = r[18];
        s[6] = r[19];
        s[7] = r[20];
        s[8] = r[21];
        s[9] = r[22];
        s[10] = r[23];
        s[11] = r[24];
        s[12] = r[25];
        s[13] = r[26];
        s[14] = r[27];
        secondPart.Rows.Add(f);
    }
    firtPart.AcceptChanges();
    secondPart.AcceptChanges();

You may add constrints to the the tables collection and/or relationships between tables in the dataset's realtionships collection.

Igor Zelaya
Thanks for the reply that's what I exactly did
How about if you mark my answer as correct : )
Igor Zelaya