Saturday, July 7, 2018

VB code update all entries in datagridview row

   Dim dr As New DialogResult
        dr = MessageBox.Show("Are you sure you want to save?", "Deskware", MessageBoxButtons.OKCancel, MessageBoxIcon.Question)
        If dr = Windows.Forms.DialogResult.OK Then
            Dim zz As Double
            zz = DataGridView1.RowCount
            ToolStripProgressBar1.Visible = True
            ToolStripProgressBar1.Minimum = 0

            Dim currentrow As New DataGridViewRow

            For Each currentrow In DataGridView1.Rows
                ToolStripProgressBar1.Value = ToolStripProgressBar1.Value + 1

                Dim strs = "Select * from Individual_loan_ledger WHERE (acct_no = '" & currentrow.Cells(0).Value.ToString & "' and Loan_no = '" & currentrow.Cells(4).Value.ToString & "' and Sched = #" & DateTimePicker1.Value.ToShortDateString & "#)"
                Dim cmds As New OleDbCommand(strs, con)
                If con.State = ConnectionState.Closed Then con.Open()
                Dim drs As OleDbDataReader = cmds.ExecuteReader
                If drs.HasRows Then
                    'Update the individual_loan_ledger table if there is record found.
                    If con.State = ConnectionState.Closed Then con.Open()
                    Dim st As String = "UPDATE [Individual_loan_ledger]SET Date_paid = #" & DateTimePicker1.Value.ToShortDateString & "#, Principal = " & currentrow.Cells(11).Value & ", Interest = 0, Balance= " & currentrow.Cells(10).Value - currentrow.Cells(11).Value & ", Penalty = 0, discount = 0, savings = 0,cbu = 0, addon1 = 0, addon2 =0,addon3 = 0 WHERE(acct_no = '" & currentrow.Cells(0).Value.ToString & "' and Loan_no = '" & currentrow.Cells(4).Value.ToString & "' and Sched = #" & DateTimePicker1.Value.ToShortDateString & "#)"
                    Dim cmd As New OleDbCommand(st, con)
                    cmd.ExecuteNonQuery()
                Else
                    'Insert new row for individual_loan_ledger if no row to update about payment or sched is not found.
                    If con.State = ConnectionState.Closed Then con.Open()
                    Dim st As String = "INSERT INTO [Individual_loan_ledger](Loan_no, Loan_type, eName, Sched, Date_paid, principal, interest,Balance,penalty, acct_no, emo, eyr )VALUES ( '" & currentrow.Cells(4).Value.ToString & "', '" & currentrow.Cells(5).Value.ToString & "', '" & currentrow.Cells(2).Value.ToString & "', #" & DateTimePicker1.Value.ToShortDateString & "#, #" & DateTimePicker1.Value.ToShortDateString & "#, " & currentrow.Cells(11).Value & ", 0, " & currentrow.Cells(10).Value - currentrow.Cells(11).Value & ", 0, '" & currentrow.Cells(0).Value.ToString & "', " & DateTimePicker1.Value.Month & ", " & DateTimePicker1.Value.Year & ")"
                    Dim cmd As New OleDbCommand(st, con)
                    cmd.ExecuteNonQuery()
                End If
               
                'Update the balance in the loan_business table.
                If con.State = ConnectionState.Closed Then con.Open()
                Dim tempbalance As Double = currentrow.Cells(10).Value - currentrow.Cells(11).Value
                Dim st3 As String = "UPDATE [Loan_business]SET ebalance = " & tempbalance & ", epay = " & currentrow.Cells(11).Value & " WHERE(([acct_no] = '" & currentrow.Cells(0).Value.ToString & "' and [fno] = '" & currentrow.Cells(4).Value.ToString & "'))"
                Dim cmd3 As New OleDbCommand(st3, con)
                cmd3.ExecuteNonQuery()
                '=======================
            Next
            ToolStripProgressBar1.Visible = False
            ToolStripProgressBar1.Value = 0
            fill2()
            checkupdatesbalance()
            con.Close()
            MsgBox("Update successful. Transaction of the days has been saved.", MsgBoxStyle.Information)

No comments:

Post a Comment

Part 7. Commercial Law. Piercing the viel. Solidary liability

Because a corporation’s existence is only by fiction of law, it can only exercise its rights and powers through its directors, officers, or...