Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
VB
For Each row As GridViewRow In GridView1.Rows

           If
               Dim studentid As String = CType(row.FindControl("Label1"), Label).Text
               studentid = sid

                 Then

               cmd.CommandText = "update feerpt " & _
                                 " set  receved=receved+@receved,balance=@balance" & _
                                  " where studentid= " & sid & ""

           Else

               Dim amount As String = CType(row.FindControl("Label4"), Label).Text
               Dim feeheadid As String = CType(row.FindControl("Label3"), Label).Text
               Dim studentid As String = CType(row.FindControl("Label1"), Label).Text
               Dim monthid As String = CType(row.FindControl("Label2"), Label).Text
               Dim receved As String = CType(row.FindControl("txtrec"), TextBox).Text

               cmd.CommandText = " insert into feerpt(feeheadid,studentid,monthid,receved,amount) " & _
                             " values (" & feeheadid & "," & studentid & "," & monthid & "," & receved & "," & amount & ")"
               cmd.ExecuteNonQuery()


           End If
               Next
Posted
Updated 10-Sep-21 23:21pm
Comments
CoderPanda 21-Mar-14 8:22am    
Please check the syntax in the IF block - condition. Seems like you are doing an assignment in the expression itself that is causing the problem.

1 solution

Look at the code:
VB
If
    Dim studentid As String = CType(row.FindControl("Label1"), Label).Text
    studentid = sid

      Then

    cmd.CommandText = "update feerpt " & _
                      " set  receved=receved+@receved,balance=@balance" & _
                       " where studentid= " & sid & ""
probably, what you meant to say was:
VB
Dim studentid As String = CType(row.FindControl("Label1"), Label).Text
If studentid = sid Then

    cmd.CommandText = "update feerpt " & _
                      " set  receved=receved+@receved,balance=@balance" & _
                      " where studentid= " & sid & ""
 
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