 |
|
อยากทราบคำสั่ง ที่ตรวจเช็คค่าซ้ำ ที่เป็นตัวอักษร |
|
 |
|
|
 |
 |
|
ต้องการตรวจสอบค่าที่มีอยู่แล้ว พอซ้ำให้แจ้งเตือน อย่างรูป ถ้าพิมพ์หินกรวดให้แจ้งเตือนว่าซ้ำ

อันนี้ code
Code (VB.NET)
If st = "add" Then
If MessageBox.Show("ต้องการบันทึกข้อมูลหรือไม่", "ยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
Dim sql As String
sql = " insert into type (Typ_id,Typ_name)"
sql &= " values ('" & txtid.Text & "',"
sql &= " '" & txtname.Text & "')"
Try
Dim cm As New OleDbCommand(sql, Cnn)
cm.ExecuteNonQuery()
MessageBox.Show("บันทึกข้อมูลเรียบร้อย", "ผลการดำเนินการ", MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As Exception
MessageBox.Show("ไม่สามารถบันทึกข้อมูลได้", "ผลการดำเนินการ", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Exit Sub
End Try
End If
Tag : .NET, VB.NET
|
|
 |
 |
 |
 |
Date :
2016-01-13 11:18:56 |
By :
erlnw001 |
View :
1430 |
Reply :
7 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตัวอย่างการเช็คซ้ำครับ
Code (VB.NET)
Dim intNumRows As Integer
strSQL = "SELECT COUNT(*) FROM customer WHERE CustomerID = '"& Me.txtCustomerID.Text &"' "
objCmd = New OleDbCommand(strSQL, objConn)
intNumRows = objCmd.ExecuteScalar()
IF intNumRows > 0 Then
Me.pnlAdd.Visible = False
Me.lblStatus.Visible = True
Me.lblStatus.Text = "CustomerID already exist."
Else
strSQL = "INSERT INTO customer (CustomerID,Name,Email,CountryCode,Budget,Used) " & _
" VALUES " & _
" ('" & Me.txtCustomerID.Text & "','" & Me.txtName.Text & "','" & Me.txtEmail.Text & "', " & _
" '" & Me.txtCountryCode.Text & "','" & Me.txtBudget.Text & "','" & Me.txtUsed.Text & "')"
objCmd = New OleDbCommand
With objCmd
.Connection = objConn
.CommandText = strSQL
.CommandType = CommandType.Text
End With
Me.pnlAdd.Visible = False
Try
objCmd.ExecuteNonQuery()
Me.lblStatus.Text = "Record Inserted"
Me.lblStatus.Visible = True
Catch ex As Exception
Me.lblStatus.Visible = True
Me.lblStatus.Text = "Record can not insert Error ("& ex.Message &")"
End Try
End IF
|
 |
 |
 |
 |
Date :
2016-01-13 13:20:23 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณครับ เดี๋ยวจะลองดู
|
 |
 |
 |
 |
Date :
2016-01-13 13:38:40 |
By :
erlnw001 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้แล้วครับ ขอบคุณครับ  
|
 |
 |
 |
 |
Date :
2016-01-18 11:16:30 |
By :
erlnw001 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|