|
|
|
ถ้า เรา จะเขียนโค้ด เซ็ก ว่าข้อมูลมีอยู่ใน ฐานข้อมูลอยู่แล้ว จะเขียน ยังไง อ่ะงับ |
|
|
|
|
|
|
|
Code (VB.NET)
Sub btnSave_Click(sender As Object, e As EventArgs)
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
End Sub
|
|
|
|
|
Date :
2011-08-29 06:12:14 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pnlAdd คืออะไรหรือครับ
|
|
|
|
|
Date :
2012-03-04 11:45:12 |
By :
Mikkola |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
มันคือ Panel (ASP.NET) ครับ ถ้าคุณเขียนบน Windows App อาจจะใช้ Label แทนครับ
|
|
|
|
|
Date :
2012-03-04 11:46:25 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|