Click here to Skip to main content
13,002,000 members (75,406 online)
Rate this:
Please Sign up or sign in to vote.
See more:
i'm having problem updating data. Data didnt updated when changes are made..
Please look at my coding

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
                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")
            End If
Posted 13-Apr-13 20:11pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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

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

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.....
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170624.1 | Last Updated 14 Apr 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100