Click here to Skip to main content
14,267,277 members
Rate this:
Please Sign up or sign in to vote.
I am trying to merge two data table dt and dt4. While using the given below code getting one error. The error is : "'column' argument cannot be null." Help me to find a proper soluion. Thank you.


protected void ddlCircle_SelectedIndexChanged(object sender, EventArgs e)
    ShadingAnalysisDataSetTableAdapters.tbl_CadEngineersTeamTableAdapter cd;
    cd = new ShadingAnalysisDataSetTableAdapters.tbl_CadEngineersTeamTableAdapter();
    DataTable dt = new DataTable();
    dt = cd.GetAvailableData(ddlCircle.SelectedValue); // Getting details of unassigned site

    int x, y;

    DataTable dt3 = new DataTable();
    dt3 = cd.GetTeam();
    y = dt3.Rows.Count;

    x = dt.Rows.Count; // counting the unassinged sites

    DataTable dt2 = new DataTable();
    dt2 = cd.GetAssignTeam(x);           //Getting team based on count

    string[] arr = new string[dt2.Rows.Count];
    int i = 0;
    foreach (DataRow r in dt2.Rows)
        arr[i] = r["Team"].ToString(); // assigning available team to array

    string[] strArr = new string[x+1]; // another array to copy arr values.

    i = 0; int j = 0;
    while (j <= x)
        strArr[j]=  arr[i] ; // copying the arr[] values into strArr[] based on count.

        if (i == y)
            i = 0;
     DataTable dt4 = new DataTable();

     foreach (string s in strArr)
          dt4.Rows.Add(s); // Converting string array strArr[] to data table dt4

     dt.Merge(dt4);  // error poppup here. Error : 'column' argument cannot be null.
     GridView2.DataSource = dt;

dt contain

State  District  SiteID  SiteName
-----  --------  ------  --------
Sate1  District1  1001     A
Sate2  District2  1002     B
Sate3  District3  1003     C

dt4 contain


I need a final output as:

State  District  SiteID  SiteName  Team
-----  --------  ------  --------  -----
Sate1  District1  1001     A       Team1
Sate2  District2  1002     B       Team2
Sate3  District3  1003     C       Team3
V5709 29-Oct-14 7:54am
you can use concepts like inner join to fetch details which will reduce your code
Rate this:
Please Sign up or sign in to vote.

Solution 2

select a.*, from table_name1 as a,table_name2 as b
aarif moh shaikh 29-Oct-14 8:31am
He asking about Data Table .. not Database Tables
Rate this:
Please Sign up or sign in to vote.

Solution 3

you can't use Merge for this Case better you could use Join in Datatable

Refer this:[^]
Rate this:
Please Sign up or sign in to vote.

Solution 4

try like this
string[] strArr = { "a", "b", "c" };
            DataTable dt = new DataTable();

            dt.Rows.Add("1", "NAME1");
            dt.Rows.Add("2", "NAME2");
            dt.Rows.Add("3", "NAME3");
            int iCount = 0;
            foreach (DataRow item in dt.Rows)
                item["Team"] = strArr[iCount];


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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100