 |
|
ข้อมูลที่เพิ่มเข้าไปใหม่ถ้ามีอยู่แล้วในฐานข้อมูลจะมีข้อความแจ้งเตือน |
|
 |
|
|
 |
 |
|
Code (VB.NET)
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.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 SqlCommand
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 :
2011-09-27 06:19:46 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้แล้วครับ ขอบคุณครับ ^^
|
 |
 |
 |
 |
Date :
2011-10-02 13:11:05 |
By :
mind_mind |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|