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
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)