Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim cmd As OleDbCommand = Nothing
Dim sqlSave As String = ""
Dim sqlUpdate As String = ""
Dim j As Integer
Dim sqlif As String = "SELECT BNLR_NUMLEVEL FROM BK_NUM_LEVEL_R WHERE BNLR_NUMLEVEL LIKE '" & Txt_Id.Text & "' "
da1 = New OleDbDataAdapter(sqlif, OBCon)
da1.Fill(ds1, "dsif")
dt1 = ds1.Tables("dsif")
j = Val(dt1.Rows.Count)
ds1.Tables("dsif").Clear()
dt1 = ds1.Tables("dsif")
If Txt_Id.Text = "" Then
MessageBox.Show("กรุณากรอกข้อมูล", "คำเตือน", MessageBoxButtons.OK, MessageBoxIcon.Information)
Txt_Id.Focus()
Exit Sub
ElseIf MessageBox.Show("ทำการบันทึก " & Txt_Id.Text & " ", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.No Then
Exit Sub
End If
Try
Catch ex As Exception
End Try
Try
If j = 0 Then
sqlSave = "INSERT INTO BK_NUM_LEVEL_R(BNLR_NUMLEVEL) VALUES( '" & Txt_Id.Text & "')"
tempshowrecord = Val(Txt_Id.Text.ToString)
cmd = New OleDbCommand(sqlSave, OBCon)
cmd.ExecuteNonQuery()
Else
sqlUpdate = "UPDATE BK_NUM_LEVEL_R SET BNLR_NUMLEVEL='" & Txt_Id.Text & "' WHERE BNLR_NUMLEVEL = '" & Txt_Id.Text & "'"
tempshowrecord = Val(Txt_Id.Text.ToString)
cmd = New OleDbCommand(sqlUpdate, OBCon)
cmd.ExecuteNonQuery()
End If
Catch ex As Exception ' กรณีประมวลผลในช่วงของ Try แล้วมีข้อผิดพลาด จะมีการกระโดด(jump) ลงมาที่บรรทัดนี้เลย เพื่อแสดงข้อผิดพลาดของโปรแกรม
MessageBox.Show(ex.Message, "ข้อผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Finally
'cleargrid()
Showrecord()
End Try
End Sub