0

hey guys. . .im having a problem with my update code in vb.net.. .
look at my screenshot attachment
the column time_out is the problem. . .
here's the code i used

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim timeout As String
        Dim user As String
        Dim tim As String

        con = New SqlConnection("Data Source=.\SQLExpress;Integrated Security=true; AttachDbFilename=C:\Users\Carlo\Desktop\OTTO Payroll System\OTTO Payroll System\OTTOdBase.mdf;User Instance=true")
        con.Open()

        user = "'" & Trim(TextBox1.Text) & "'"
        timeout = "'" & Trim(Label1.Text) & "'"
        Try
            If CType(Me.ACCESSTableAdapter.LoginQuery(Me.TextBox1.Text, _
                     Me.TextBox2.Text), Integer) > 0 Then

                tim = "UPDATE TIME SET Time_Out = " & timeout & " WHERE EXISTS (SELECT Sessions FROM TIME WHERE Sessions = Sessions)"
                com = New SqlCommand(tim, con)
                com.ExecuteNonQuery()
                MsgBox("Hachoo!")

            Else
                MsgBox("Invalid Username and/or Password!.")

            End If
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try

        Dim query As String
        query = "SELECT ATTEND.TimeStart, TIME.Time_In FROM ATTEND, TIME WHERE ATTEND.Emp_ID = TIME.Emp_ID WHERE TIME.Minutes_late IN (UPDATE TIME SET TIME.Minutes_Late WHERE TIME.Time_In - ATTEND.TimeStart)"
    End Sub

what seems to be the problem? help please. . .

Attachments tablesuy.jpg 43.21 KB
2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by Teme64
0

In your update statement UPDATE TIME SET Time_Out = " & timeout & " WHERE EXISTS (SELECT Sessions FROM TIME WHERE Sessions = Sessions) condition EXISTS (SELECT Sessions FROM TIME WHERE Sessions = Sessions) is true for each row because Sessions = Sessions is always true. That's why your statement updates each row.

You should change Sessions = Sessions to something else, like Sessions = " & ThisUserSession & " or similar.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.