Click here to Skip to main content
16,018,802 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have 2 datagridview . both datagridview values some same and some different if values different then put one of the datagridview field 0

my code like this but it n0t work

C#
for (int k = 0; k < dataGridView3.Rows.Count; k++)
             {
 for (int i = 0; i < dataGridView1.Rows.Count; i++)
    {

  string j12 = dataGridView3.Rows[k].Cells[1].Value.ToString();

   string J13 = dataGridView3.Rows[k].Cells[2].Value.ToString();
   double m = double.Parse(J13)             if (dataGridView1.Rows[i].Cells[0].Value.ToString() == j12)    
 {

                                                                        dataGridView1.Rows[i].Cells[2].Value = m;
                                                                        dataGridView1.Rows[i].Cells[3].Value = m;
         }
      else
  {
                                                                        dataGridView1.Rows[i].Cells[2].Value = "0.00";
                                                                        dataGridView1.Rows[i].Cells[3].Value = "0.00";

 }
}


input like that

VB
Table A
  id   column
  1     data1
  2     data2
  3     data3
  4     data4

Table B
  id   column
  1     data10
  3     data30


output like that

SQL
Table C
  id    column
  1        0
  2      data2
  3        0
  4      data4
Posted
Updated 30-Jun-14 23:57pm
v2
Comments
George Jonsson 1-Jul-14 3:30am    
Do you use a DataTable as the data source for the grid?
If so, it is easier to work on the data table.
Member 10285877 1-Jul-14 3:32am    
ya sir how sir please send sample please
George Jonsson 1-Jul-14 3:56am    
Look at this similar question
http://stackoverflow.com/questions/15713243/compare-two-datatables-and-select-the-rows-that-are-not-present-in-second-table
CHill60 3-Jul-14 7:40am    
Your question about comparing a date to the 10th of the month has been closed because people reported it as not clear. If you repost the question be sure to add the details you put into the comments - i.e. make it clear that that you are trying to determine how many days until/since the 10th of the month. I do have a solution for you if you repost the question and let me know by replying to this comment

1 solution

 
Share this answer
 
Comments
Member 10285877 1-Jul-14 6:03am    
sir i want zero if not match please help
Nguyen.H.H.Dang 1-Jul-14 21:13pm    
The easiest way is looping.

You have DataTable A and DataTable B, right ?

First, declare a result DataTable C

So, just loop row by row, compare A's rows with B's rows, if match, add that row to C. If not match, add a row with 0 value to C.

Done !!! :)

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