update records from datagridview column

  • Thread starter Thread starter Omi4u
  • Start date Start date
O

Omi4u

Guest
i am working on "cash payment" module

and here i am entering 5 accounts which will be debit after i save it. now i am using below code that will update all accounts at ones but can you check what mistake im doing becz this code is not working it saving the record but not hitting the accounts .


For Each row As DataGridViewRow In CashpaymentDataGridView.Rows
If Not row.IsNewRow Then
con = New SqlConnection(appx.myconnection)
con.Open()
Dim ctx As String = "select Account_Title from COA where Account_Title=@d1 and Account_Title=@d2"
cmd = New SqlCommand(ctx)
cmd.Connection = con
cmd.Parameters.AddWithValue("@d1", row.Cells(3).Value)
cmd.Parameters.AddWithValue("@d2", row.Cells(5).Value)
rdr = cmd.ExecuteReader()
If (rdr.Read()) Then

con = New SqlConnection(appx.myconnection)
con.Open()
Dim cb2 As String = "Update COA set opening_balance = opening_balance + " & row.Cells(3).Value & " where AccountID=@d1"
Dim cb3 As String = "Update COA set opening_balance = opening_balance - " & row.Cells(5).Value & " where AccountID=@d2"
cmd = New SqlCommand(cb2 And cb3)
cmd.Connection = con
cmd.Parameters.AddWithValue("@d1", (row.Cells(3).Value))
cmd.Parameters.AddWithValue("@d2", row.Cells(5).Value)
cmd.ExecuteReader()
con.Close()
End If
End If

Continue reading...
 
Back
Top