Click here to Skip to main content
11,708,865 members (73,595 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: VB.NET
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 at 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
0 Sergey Alexandrovich Kryukov 319
1 Maciej Los 235
2 Mika Wendelius 170
3 OriginalGriff 163
4 Peter Leow 139
0 OriginalGriff 9,253
1 Sergey Alexandrovich Kryukov 8,562
2 CPallini 5,189
3 Maciej Los 4,966
4 Mika Wendelius 3,856

Advertise | Privacy | Mobile
Web02 | 2.8.150819.1 | Last Updated 14 Apr 2013
Copyright © CodeProject, 1999-2015
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