Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Dim sqlAdd As String
Dim sqlEdit As String
Dim comAdd As New OleDbCommand
Select Case btnChk
Case "Add"
If (txtName.Text = "") Or (txtPassword.Text = "") Or (txtAdname.Text = "") Or (txtTel.Text = "") Or (txtAddress.Text = "") Then
MsgBox("โปรดป้อนข้อมูลให้ครบ")
txtName.Focus()
Exit Sub
End If
sqlAdd = "Insert into tblAdmin(Adm_id,Adm_username,Adm_password,Adm_name,Adm_phone,Adm_address)"
sqlAdd &= " Values('" & txtID.Text & "',"
sqlAdd &= " '" & txtName.Text & "',"
sqlAdd &= " '" & txtPassword.Text & "',"
sqlAdd &= " " & txtAdname.Text & ","
sqlAdd &= " " & txtTel.Text & ","
sqlAdd &= " '" & txtAddress.Text & "')"
With comAdd
.CommandType = CommandType.Text
.CommandText = sqlAdd
.Connection = Conn
.ExecuteNonQuery() ***********เอ่อเร่อตรงนี้ค่ะ*************
End With
MsgBox("บันทึกข้อมูลเรียบร้อย")
ShowAllfrmAdmin()
Case "Update"
sqlEdit = "Update tblAdmin "
sqlEdit &= " Set Adm_username ='" & txtName.Text & "', "
sqlEdit &= " Adm_password ='" & txtPassword.Text & "',"
sqlEdit &= "Adm_name =" & txtAdname.Text & ","
sqlEdit &= " Adm_phone=" & txtTel.Text & ","
sqlEdit &= " Adm_address='" & txtAddress.Text & "'"
sqlEdit &= " Where (Adm_ID=" & txtID.Text & ") "
With comAdd
.CommandType = CommandType.Text
.CommandText = sqlEdit
.Connection = Conn
.ExecuteNonQuery()
End With
MsgBox("แก้ไขข้อมูลเรียบร้อยแล้ว")
ShowAllfrmAdmin()
Case Else
MsgBox("ระบบไม่มีการทำงาน")
End Select
btnInsert.Enabled = True
btnUpdate.Enabled = True
btnDelete.Enabled = True
btnSave.Enabled = False
btnCancel.Enabled = False
txtID.Text = ""
txtName.Text = ""
txtPassword.Text = ""
txtAdname.Text = ""
txtTel.Text = ""
txtAddress.Text = ""
txtName.Focus()
End Sub
รบกวนช่วยดูโค้ชหน่อยค่ะ เอ่อเร่อ ตรง ExecuteNonQuery ไม่รุ้จะแก้ยังไงดีค่ะ รบกวนผู้รู้ช่วยตอบด้วยนะค่ะ ขอบคุณค่ะ
Dim sqlAdd As String
Dim sqlEdit As String
Dim comAdd As New OleDbCommand
Select Case btnChk
Case "Add"
If (txtName.Text = "") Or (txtPassword.Text = "") Or (txtAdname.Text = "") Or (txtTel.Text = "") Or (txtAddress.Text = "") Then
MsgBox("โปรดป้อนข้อมูลให้ครบ")
txtName.Focus()
Exit Sub
End If
sqlAdd = "Insert into tblAdmin(Adm_id,Adm_username,Adm_password,Adm_name,Adm_phone,Adm_address)"
sqlAdd &= " Values('" & txtID.Text & "',"
sqlAdd &= " '" & txtName.Text & "',"
sqlAdd &= " '" & txtPassword.Text & "',"
sqlAdd &= " " & txtAdname.Text & ","
sqlAdd &= " " & txtTel.Text & ","
sqlAdd &= " '" & txtAddress.Text & "')"
With comAdd
.CommandType = CommandType.Text
.CommandText = sqlAdd
.Connection = Conn
.ExecuteNonQuery() ***********เอ่อเร่อตรงนี้ค่ะ*************
End With
MsgBox("บันทึกข้อมูลเรียบร้อย")
ShowAllfrmAdmin()
Case "Update"
sqlEdit = "Update tblAdmin "
sqlEdit &= " Set Adm_username ='" & txtName.Text & "', "
sqlEdit &= " Adm_password ='" & txtPassword.Text & "',"
sqlEdit &= "Adm_name =" & txtAdname.Text & ","
sqlEdit &= " Adm_phone=" & txtTel.Text & ","
sqlEdit &= " Adm_address='" & txtAddress.Text & "'"
sqlEdit &= " Where (Adm_ID=" & txtID.Text & ") "
With comAdd
.CommandType = CommandType.Text
.CommandText = sqlEdit
.Connection = Conn
.ExecuteNonQuery()
End With
MsgBox("แก้ไขข้อมูลเรียบร้อยแล้ว")
ShowAllfrmAdmin()
Case Else
MsgBox("ระบบไม่มีการทำงาน")
End Select
btnInsert.Enabled = True
btnUpdate.Enabled = True
btnDelete.Enabled = True
btnSave.Enabled = False
btnCancel.Enabled = False
txtID.Text = ""
txtName.Text = ""
txtPassword.Text = ""
txtAdname.Text = ""
txtTel.Text = ""
txtAddress.Text = ""
txtName.Focus()
End Sub