Dim intNumRows As Integer
strSQL = "SELECT COUNT(*) FROM customer WHERE CustomerID = '"& Me.txtCustomerID.Text &"' "
objCmd = New SqlCommand(strSQL, objConn)
intNumRows = objCmd.ExecuteScalar()
IF intNumRows > 0 Then
Me.lblStatus.Text = "CustomerID already exist."
Else
' /// Do
End IF
Private Sub save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles save.Click
Dim sav As MsgBoxResult
Dim sqladd As String
Dim cm As New SqlCommand
Conn = New SqlConnection("Data Source=TOSHIBA-PC\SQLEXPRESS;Initial Catalog=rfid2;Integrated Security=True")
Conn.Open()
If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Then
MessageBox.Show("คุณยังกรอกข้อมูลไม่ครบถ้วน")
Exit Sub
End If
sav = MessageBox.Show("คุณต้องการบันทึกข้อมูลหรือไม่?", "rfid", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If sav = MsgBoxResult.Yes Then
sqladd = "INSERT INTO rfidtable(CardSN,Firstname,Surname)"
sqladd &= "VALUES ( ' " & TextBox1.Text & " ',' " & TextBox2.Text & " ',' " & TextBox3.Text & " ') "
With cm
.CommandType = CommandType.Text
.CommandText = sqladd
.Connection = Conn
.ExecuteNonQuery()
End With
End If
MessageBox.Show("บันทึกข้อมูลเรียบร้อย", "rfid", MessageBoxButtons.OK, MessageBoxIcon.Information)
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
End Sub