Click here to Skip to main content
15,895,423 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
i'm having problem updating data. Data didnt updated when changes are made..
Please look at my coding

VB
cmd2 = New SqlCommand("Select * From TLoct Where Loct= 'TST1' And PCode=@PCode And Batch= @Batch And Run=@Run And OnHand >0 ", cn2)
            cmd2.Parameters.AddWithValue("@PCode", rs.Tables("TPlt").Rows(0).Item("PCode"))
            cmd2.Parameters.AddWithValue("@Batch", txtBatch.Text)
            cmd2.Parameters.AddWithValue("@Run", txtRun.Text)
            Dim sqlDa2 As SqlDataAdapter
            sqlDa2 = New SqlDataAdapter(cmd2)
            Dim rs2 As DataSet = New DataSet
            sqlDa2.Fill(rs2, "TLoct")
            If rs2.Tables("TLoct").Rows.Count = 0 Then
                MsgBox("No stock at TST1", MsgBoxStyle.Critical)
                Exit Sub
            Else
                Dim dt As DataTable = rs2.Tables("TLoct")
                'MsgBox(rs2.Tables("TLoct").Rows(0).Item("OutputQty") + rs.Tables("TPlt").Rows(0).Item("FullQty") + rs.Tables("TPlt").Rows(0).Item("LsQty"))
                dt.Rows(0)("OutputQty") = rs2.Tables("TLoct").Rows(0).Item("OutputQty") + rs.Tables("TPlt").Rows(0).Item("FullQty") + rs.Tables("TPlt").Rows(0).Item("LsQty")
                dt.Rows(0)("OnHand") = dt.Rows(0)("OnHand") - rs.Tables("TPlt").Rows(0).Item("FullQty") - rs.Tables("TPlt").Rows(0).Item("LsQty")
                dt.Rows(0)("EditUser") = txtEmpNo.Text & "@" & txtName.Text
                dt.Rows(0)("EditDate") = Format(Now, "dd-mmm-yyyy")
                dt.Rows(0)("EditTime") = Format(Now, "hh:mm")
                dt.AcceptChanges()
            End If
Posted

1 solution

However you have not written the error which is coming but still after watching your code i found following suspicious line which may cause in not updation

C#
dt.Rows(0)("OnHand") = dt.Rows(0)("OnHand") - rs.Tables("TPlt").Rows(0).Item("FullQty") - rs.Tables("TPlt").Rows(0).Item("LsQty")


modify it as following

C#
dt.Rows(0)("OnHand") = val(dt.Rows(0)("OnHand")) - val(rs.Tables("TPlt").Rows(0).Item("FullQty")) - val(rs.Tables("TPlt").Rows(0).Item("LsQty"))



i hope it works.....
 
Share this answer
 
v2
Comments
Syahrul Anuar 14-Apr-13 21:37pm    
i got errors - update requires a valid insertcommand when passed datarow collection with modified rows,
i have put val()to the formula..
still got that message.. i used VB 6.0 before.. Tq

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