My If Else statement in VB.net is randomly displaying either of the If or ElseIf condition that I made.
What I'm trying to do is when a DataGridView checkbox is selected and the LinkLabel is clicked, The system will get the row which is selected and it will update the "EditTime" column to either "ds" or "en" depending on what is already in the column
So, if the data in the "EditTime" column is set to "ds", the If Else condition should change it to "en" and vice versa.
Dim en As OleDbCommand = New OleDbCommand("SELECT * FROM [Roster1]", myConnection)
Dim d As OleDbDataReader = en.ExecuteReader
Dim edt As String = ""
While d.Read
edt = d("EditTime").ToString
End While
Dim CheckedRows =
(
From Rows In AdminTabDisplay.Rows.Cast(Of DataGridViewRow)()
Where CBool(Rows.Cells("ck").Value) = True
).ToList
If CheckedRows.Count > 0 Then
Dim sb As New System.Text.StringBuilder
For Each row As DataGridViewRow In CheckedRows
sb.AppendLine(row.Cells("Employee ID").Value.ToString)
Next
If edt = "ds" Then
Dim st As String = sb.ToString
Dim value As Integer = CInt(st)
Dim cmd As OleDbCommand = New OleDbCommand("UPDATE [Roster1] SET [EditTime] = @pw WHERE [Employee ID] = @v", myConnection)
cmd.Parameters.AddWithValue("@pw", "en")
cmd.Parameters.AddWithValue("@v", value)
cmd.ExecuteNonQuery()
MsgBox("Edit enabled!")
ElseIf edt = "en" Then
Dim st As String = sb.ToString
Dim value As Integer = CInt(st)
Dim cmd As OleDbCommand = New OleDbCommand("UPDATE [Roster1] SET [EditTime] = @pw WHERE [Employee ID] = @v", myConnection)
cmd.Parameters.AddWithValue("@pw", "ds")
cmd.Parameters.AddWithValue("@v", value)
cmd.ExecuteNonQuery()
MsgBox("Edit disabled!")
End If
This is my code. Yet, the output seems to be a bit randomized.
Aucun commentaire:
Enregistrer un commentaire