Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I wrote this code for Compare 2 datagridview's data but i am facing some error

I want to Compare Each Row of DGV1 to All DGV2 Rows.....



Here is My Code..............................
please Help me to Improve this...... This is Basically School Application


VB
Private Sub btncheck_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncheck.Click

           Dim mytable As New DataTable
           CMD.Connection = CN
           CMD.CommandText = "Select classname,studentname,fname,grno from students where classname='" & Me.ComboBox2.Text & "'"
           DataR = CMD.ExecuteReader

           Dim i As Integer
           For i = 0 To mytable.Rows.Count - 1
               DataR.Read()
       Next
       mytable.Load(DataR)
       DGV2.DataSource = mytable


       DGV2.Columns.Add("feemonth", "Fee Month")
       DGV2.Columns.Add("status", "Status")


       For i = 0 To mytable.Rows.Count - 1
           Dim i2 As Integer
           For i2 = 0 To DGV2.Rows.Count - 1

           Next

           With DGV2

               .Columns("classname").HeaderCell.Value = ("Class")
               .Columns("studentname").HeaderCell.Value = ("Student Name")
               .Columns("fname").HeaderCell.Value = ("Father's Name")
               .Columns("grno").HeaderCell.Value = ("GR NO")

           End With

           If DGV1.Rows.Count > 0 Then

           End If






           If DGV1.Rows.Count = 0 Then
               DGV2.Rows(i).Cells("status").Value = "Un Paid"
               DGV2.Rows(i).Cells("feemonth").Value = Me.ComboBox1.Text
               DGV2.Rows(i).Cells("status").Style.ForeColor = Color.Red



           ElseIf DGV1.CurrentRow.Cells("name").Value.ToString = DGV2.Rows(i).Cells("studentname").Value.ToString Then


               DGV2.Rows(i).Cells("status").Value = "Paid"
               DGV2.Rows(i).Cells("status").Style.ForeColor = Color.Blue
               DGV2.Rows(i).Cells("feemonth").Value = Me.ComboBox1.Text
           Else
               DGV2.Rows(i).Cells("status").Value = "UN Paid"
               DGV2.Rows(i).Cells("status").Style.ForeColor = Color.Red

               DGV2.Rows(i).Cells("feemonth").Value = Me.ComboBox1.Text
           End If


       Next

       DataR.Close()

   End Sub
Posted
Updated 17-Jun-13 3:58am
v2
Comments
Surendra Adhikari SA 17-Jun-13 9:57am    
what is the problem with your code?? what you want?
Muhammad Anis 0300 17-Jun-13 10:09am    
hey Sureendra.......... Please Help
Muhammad Anis 0300 17-Jun-13 10:02am    
in this code i can't check each row of DGV1 in all Rows of DGV2
Muhammad Anis 0300 17-Jun-13 10:03am    
And I want to Check Each row of DGV1 in all rows of DGV2 with Loop
Muhammad Anis 0300 17-Jun-13 10:03am    
Please Help me to Write the Correct Code!!!!!!!

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