Join the social network of Tech Nerds, increase skill rank, get work, manage projects...

 1 Answer(s)

  • As per my understanding you want to merge two column values from two different DataTables into a single DataTable.

    In a simplest manner you can iterate through each row of the two DataTables to be merged and then save merged values into a result DataTables

    Please have a look at the sample code below, in case you have any problem, please let me know.

            //Inserting value in the first DataTable dt1
            DataTable dt1 = new DataTable();
            DataRow dr = dt1.NewRow();
            dr["FirstName"] = "FirstName_1";
            dr = dt1.NewRow();
            dr["FirstName"] = "FirstName_2";
            //Inserting value in the second DataTable dt2
            DataTable dt2 = new DataTable();
            DataRow dr1 = dt2.NewRow();
            dr1["LastName"] = "LastName_1";
            dr1 = dt2.NewRow();
            dr1["LastName"] = "LastName_2";
            //Merging the values of two columns into another DataTable dt3
            DataTable dt3 = new DataTable();
            DataRow dr3;
            for (int i = 0; i < dt1.Rows.Count; i++)
                dr3 = dt3.NewRow();
                dr3["Name"] = dt1.Rows[i]["FirstName"].ToString() + " " + dt2.Rows[i]
                dt3.Rows.InsertAt(dr3, i);
Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: