반응형
Private Sub Button2_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Button2.Click을 처리합니다.
Dim remarks As String
Dim am_OUT As String = "11:30:01 AM"
If LblTime.Text >= am_OUT Then
remarks = "OVERTIME"
Else
remarks = "PRESENT"
End If
sql = "UPDATE attendance SET am_out=@am_out, noon_remarks=@noon_remarks " & _
"WHERE id_no= '" & Txtid.Text & "'AND date LIKE '" & LblDate.Text & "'and am_out is null"
Try
With com
.Connection = con
.CommandText = "SELECT * FROM attendance WHERE id_no LIKE '" & Txtid.Text & "' AND date LIKE '" & LblDate.Text & "'AND am_out is NOT NULL"
End With
com.Parameters.Add(New MySqlParameter("@am_out", LblTime.Text))
com.Parameters.Add(New MySqlParameter("@noon_remarks", remarks))
com.ExecuteNonQuery()
If remarks = "OVERTIME" Then
MessageBox.Show("You have little overtime")
ElseIf remarks = "PRESENT" Then
MessageBox.Show("You Log out on time")
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
수업 종료
mysql에서 데이터베이스 테이블을 업데이트 할 수 없습니다. mysql 데이터베이스에는 이미 amin 및 am remarks가 있습니다.
해결 방법
com
개체가 MySqlCommand라고 가정합니다. 이 경우 라인
.CommandText = "SELECT * FROM attendance WHERE id_no LIKE '" & Txtid.Text & "' AND date LIKE '" & LblDate.Text & "'AND am_out is NOT NULL"
SELECT 문이며이 명령이 실행될 때 아무것도 업데이트 할 수 없습니다.
쿼리의 모든 부분에 대해 매개 변수화 된 쿼리를 올바르게 구현하고 물론 레코드를 업데이트하는 올바른 문을 사용하는 것이 좋습니다.
sql = "UPDATE attendance SET am_out=@am_out, noon_remarks=@noon_remarks " & _
"WHERE id_no= @id AND date LIKE @dt and am_out is null"
Try
With com
.Connection = con
.CommandText = sql
.Parameters.AddWithValue("@am_out",LblTime.Text)
.Parameters.AddWithValue("@noon_remarks",remarks)
.Parameters.AddWithValue("@id",Txtid.Text )
.Parameters.AddWithValue("@dt",Convert.ToDateTime(LblDate.Text ))
End With
com.ExecuteNonQuery()
참조 페이지 https://stackoverflow.com/questions/21469167
반응형
'MySql' 카테고리의 다른 글
MySQL Workbench에서 잘못된 변수 구문을 선언 하시겠습니까? (0) | 2020.12.11 |
---|---|
MySQL IFNULL 질문 (0) | 2020.12.11 |
MySQL MySql 구문 오류 : 1 행의 ''근처에 SQL 구문에 오류가 있습니다. (0) | 2020.12.11 |
MySQL 동적 파티셔닝 + CREATE AS on HIVE (0) | 2020.12.11 |
MySQL Tomcat에 Pentaho BI 5.0.1을 설치하는 방법 (0) | 2020.12.11 |
댓글