zuni786 0 Newbie Poster

Hi First of all i would like to say is, i am a fresher to this vb.net.. having one project in hand. But as i dont know the code for using a datagridview i am asking your help. In my sqlserver table "EmployeeDetails" we have so many columns. In that Mainly the three Columns are "EmpName", Leave Allowed and Leave Balance.
Here the employee has been restricted to take only 30 days leave in a month. Consider in a company they have % employee. 3 among them, worked on 2 days during Holidays. Employee A has 10 leave Balance and Employee B has 8 Leave Left. This 3 columns will be shown in a Datagridview along with Check box column. Now HR decides to give 2 days Componsate to leave for those 3 Employee. so she will select the Check box infront of an employee Name. In a text box (how much leave to be added) if she mention 2, then leave balance of those 3 should be added by 2. Employee A leave balance will be 12 and Employee B balance would be 10. so HR select those particular employee, and she mention 2 in the text box and click on Update button. Now how to update the LeaveBalance column in Sql Table? Here is the code what i have mentioned and went wrong..Click Here

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click

Dim sqlIns As String
        Dim n As Integer = 1

        If chkSelect.Checked = True Then
            sqlIns = "SELECT EmpName,LeaveAll,LeaveBal from LeaveDetails "
            Dim strSQL As String
            Dim Count As Double
            Dim totPasCount As Double = 0
            Dim row As DataGridViewCheckBoxCell
            strSQL = "Select LeaveBal from LeaveDetails where EmpName = '" & row("EmpName").Value & "'"
            Dim RsPCount As New ADODB.Recordset
            If RsPCount.State = 1 Then RsPCount.Close()
            RsPCount.Open(strSQL, Con, ADODB.CursorTypeEnum.adOpenForwardOnly, ADODB.LockTypeEnum.adLockReadOnly)
            If RsPCount.EOF = False Then
                totPasCount = Val(RsPCount(0).Value.ToString)
            End If
            RsPCount.Close()
            RsPCount = Nothing
            Count = totPasCount + Val(txtCount.Text)

            For Each row As DataGridViewRow In DGVEmployee.Rows
                If row.Cells("EmpName").Value Then
                    sqlIns = "Update leave details set LeaveBal = '" & Count & "' where "I DONT KNOW HOW TO MENTION THE DATAGRID CELL HERE"


                End If

            Next
            Dim insRs As New ADODB.Recordset
            If insRs.State = 1 Then insRs.Close()
            insRs.Open(sqlIns, Con, ADODB.CursorTypeEnum.adOpenForwardOnly, ADODB.LockTypeEnum.adLockReadOnly)
            While insRs.EOF = False
                sqlIns = "UPDATE LeaveDetails Set LeaveBal "

                Con.Execute(sqlIns)
                insRs.MoveNext()
                n = n + 1
            End While
            insRs.Close()
            insRs = Nothing

        End If
    End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.