locked
How to match items between SQL tables, using foreach loop RRS feed

  • Question

  • hi,

    I have a DataGridView (dgvStaff) that displays staff records, and from another SQL table I have another DataGridView (dgvNotes)

    Notes holds many notes so i only want ones with a FileID of 'STF' and then I want to match staff initials from dgvStaff with staffInitials from dgvNotes. There is only one note per staff member.

    so what I am asking is how can I make the match between the two, I suppose it would be a foreach statement with an IF statement inside.

    Many Thanks for your help


    Ryan

    Monday, August 6, 2012 12:14 PM

Answers

  • This is what you ask for

                string comparevalue;
                foreach (DataGridViewRow dr1 in dataGridView1.Rows)
                {
                    comparevalue = dr1.Cells["columnname"].ToString();
    
                    foreach(DataGridViewRow dr2 in dataGridView2.Rows)
                    {
                        if(comparevalue == dr2.Cells["columnname"].ToString())
                            //do something
                    }
    
                }


    //SFP

    Monday, August 6, 2012 12:30 PM