|
|
|
รบกวนครับ เช็คข้อมูลจากรหัสที่กรอกถ้ามีข้อมูลอยู่แล้วให้ update ลงไปแต่ถ้ายังไม่มีให้ insert ลงไป |
|
|
|
|
|
|
|
ตัวอย่างน่ะครับ
Code (VB.NET)
Dim intNumRows As Integer
strSQL = "SELECT * FROM customer WHERE CustomerID = '"& Me.txtCustomerID.Text &"' "
objCmd = New MySqlCommand(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 MySqlCommand
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
Go to : ASP.NET MySQL Check Already Exists Add/Insert Record
|
|
|
|
|
Date :
2011-03-28 15:36:28 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|