Click here to Skip to main content
16,005,037 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
Protected Sub savebtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles savebtn.Click


        Dim cmd2 As New SqlCommand With {.Connection = Hari.Utility.dbutility.Con}


        For Each row As GridViewRow In GridView1.Rows

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




            cmd.CommandText = "select * from feerpt where studentid=" & studentid & " and monthid=" & monthid & " and feeheadid=" & feeheadid & ""

            Dim dr = cmd.ExecuteReader



            If dr.HasRows Then
                Dim pre As Integer
                While dr.Read

                    pre = dr.Item("receved")
                End While

                Dim newrec As Integer = CDbl(receved) + pre
                dr.Close()
                cmd.CommandText = "update feerpt set receved=" & newrec & " where studentid=" & studentid & ""
                cmd.ExecuteNonQuery()

            Else
                dr.Close()
                cmd2.CommandText = " insert into feerpt(feeheadid,studentid,monthid,receved,amount) " & _
                          " values (" & feeheadid & "," & studentid & "," & monthid & "," & receved & "," & amount & ")"

                cmd2.ExecuteNonQuery()

            End If

            dr.Close()


        Next


    End Sub
End Class
Posted
Comments
CHill60 22-Mar-14 9:57am    
A word of advice about how you have constructed your sql commands. You are leaving yourself vulnerable to SQL Injection - use parameterised queries instead - examples here http://www.dotnetperls.com/sqlclient[^]

1 solution

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