Hello EveryBody,

The code below encounter error when no record is existing on the table. Do I need To make another query to determine if the record exist before issuing the SQL delete command ? Thank U.

VB Code:
  1. Public Function DeleteCreditCard(ByVal xBranchCode As String, ByVal xTrans_No As String) As String
  2.         Dim objKeyCommand As SqlCommand
  3.         Dim objConn As SqlConnection
  4.         Dim objDA As SqlDataAdapter
  5.         Dim strSQL As String
  6.  
  7.         objConn = New SqlConnection("SERVER=SirlitzServer;Database=dbSirlitz;UID=sa")
  8.         objKeyCommand = New SqlCommand
  9.         strSQL = "DELETE FROM arCreditCard WHERE BranchCode = '" & CInt(xBranchCode) & "' AND Trans_No = '" & CInt(xTrans_No) & "'"
  10.         objConn.Open()
  11.         objKeyCommand.CommandText = strSQL
  12.         objKeyCommand.CommandType = CommandType.Text
  13.         objKeyCommand.Connection = objConn
  14.         objKeyCommand.ExecuteNonQuery()
  15.         objKeyCommand = Nothing
  16.         objConn.Close()