Click here to Skip to main content
15,901,426 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I have two datasets say ds1 and ds2, I want to add only some selected rows(random rows) say 1st row , 3rd rows and 5th row in ds1 to ds2 how can i do it??
Posted
Updated 27-Jul-13 21:22pm
v2
Comments
Jameel VM 28-Jul-13 3:05am    
did you try anything?
naveend915 28-Jul-13 3:24am    
yup i did like this

for (int intCount = 0; intCount < rowCount; intCount++)
{
string id = ds.Tables[0].Rows[intCount]["MUid"].ToString();


ds1 = adm.getUserProfile(Convert.ToInt32(id));

foreach (DataRow dr in ds1.Tables[0].Rows)
{
ds2.Tables[0].Rows.Add(dr.ItemArray);
}

}
getting error like this
input array is longer than the number of columns in this table

 
Share this answer
 
Comments
naveend915 28-Jul-13 3:22am    
I dont wanna copy everything i just want to copy some random rows
Maciej Los 28-Jul-13 15:59pm    
And what? Have you tried code from above link?
Maciej Los 28-Jul-13 15:59pm    
+5!
Good link ;)
Adarsh chauhan 31-Jul-13 5:03am    
Nice link... my vote of 5
C#
tablename.Columns.Add("columnName1");
tablename.Columns.Add("columnName2");
.
.
.
tablename.Columns.Add("columnNamen");

//note - should have same number of column and even column name that as the other table row to be copied or added

for (int intCount = 0; intCount < rowCount; intCount++)
            {
                string id = ds.Tables[0].Rows[intCount]["MUid"].ToString();


                ds1 = adm.getUserProfile(Convert.ToInt32(id));

                foreach (DataRow dr in ds1.Tables[0].Rows)
                {
                    ds2.Tables[0].Rows.Add(dr.ItemArray);
                }
                
            }
 
Share this answer
 
C#
tablename.Columns.Add("columnName1");
tablename.Columns.Add("columnName2");
.
.
.
tablename.Columns.Add("columnNamen");

//note - should have same number of column and even column name that as the other table row to be copied or added

for (int intCount = 0; intCount < rowCount; intCount++)
            {
                string id = ds.Tables[0].Rows[intCount]["MUid"].ToString();


                ds1 = adm.getUserProfile(Convert.ToInt32(id));

                foreach (DataRow dr in ds1.Tables[0].Rows)
                {
                    ds2.Tables[0].Rows.Add(dr.ItemArray);
                }
                
            }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900