Click here to Skip to main content
15,916,846 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
I tried the below but I don't get the values of Matching, the cells are empty.

C#
t1= t2.Clone();
match2 = t1.NewRow();
t1.Columns.Add("Matching");

foreach(DataRow r in t1.Rows)
{
n = tags.Select("Title= '" + r["Title"] + "'");
    foreach (DataRow roo in n)
    {
         t1.ImportRow(roo);
         match2["Matching"] = getscore();
    }
}
Posted
Updated 22-May-14 5:10am
v2
Comments
ZurdoDev 21-May-14 16:45pm    
What exactly is wrong?
Member 10672813 21-May-14 17:41pm    
Column Matching is empty?

After you add a new row you should add value for each of all its columns, and especially for its PKs fields.
 
Share this answer
 
You should be using Copy() instead of Clone(). Clone only copies the structure but copy method copies both structure and data.

So use

t1 = t2.Copy();

instead of

t1= t2.Clone();
 
Share this answer
 
Comments
Pravuprasad 22-May-14 2:03am    
It's completely copy() instead of clone() because clone() only copies the definition but not data . While copy() does both .
Bangi Blore 22-May-14 12:32pm    
t1=t2.copy()
<>>>>>>


t1=t2.copy()
 
Share this answer
 
you can modify your code like this

C#
t1= t2.Clone();

t1.Columns.Add("Matching");

foreach(DataRow r in t1.Rows)
{
n = tags.Select("Title= '" + r["Title"] + "'");
    foreach (DataRow roo in n)
    {
         t1.ImportRow(roo);
        // match2["Matching"] = getscore();
    }
 foreach (DataRow roo in t1)
    {
         
        roo["Matching"] = getscore();
    }
}



or to add a column to a data table you can follow the below code

C#
DataTable addNewColumn(DataTable t1)
    {
        // add a column to a table
        t1.Columns.Add("qty");

        int i = 1;
        foreach (DataRow dr1 in t1.Rows)
        {

            dr1["qty"] = i++;
        }

        return t1;

    }
 
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