Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Experts,

I have a windows Forms application. I am using my DB2 Database connection and Here is my code. Code executes without any error. But when I see in Database I can still see the record which is claimed to be deleted. Meaning it is not deleted.

VB
Dim cm As New iDB2Command
   Dim da As New iDB2DataAdapter

 cm = dbclass.getCommand("Delete from TESTDATA.VXWFEATURE  where I001TRLN=@Tireline and FECLS=@selClass")
         cm.Parameters.Add("@Tireline", iDB2DbType.iDB2VarChar).Value = Tireline
         cm.Parameters.Add("@selClass", iDB2DbType.iDB2Decimal).Value = selClass


Using cn As iDB2Connection = cm.Connection
       cn.Open()
       cm.ExecuteNonQuery()
       success = True
     End Using


Can anyone help me with this please?
Posted
Comments
ZurdoDev 27-Apr-15 13:18pm    
If it executes, then it deletes. I suggest double-checking your parameters.
PIEBALDconsult 27-Apr-15 13:23pm    
I don't see where the Command is associated with the Connection.
sudevsu 27-Apr-15 14:40pm    
Seriously, everything is perfect. I was just fed up and behaved liked stupid. I closed everything and reopened my Visual Studio and executed it worked. I don't know whats wrong. But It is working fine now. Thanks all. I wish I myself can down vote my question :-) :-) :-). Such a pain looking for no exception issue...

1 solution

There are two potential causes:

1) The values you're supplying to the WHERE-clause don't actually match any record.

2) DB2 may require an explicit transaction to be committed in order to not roll back your DELETE-statement. I actually don't know if this is the case or not - but it's good practice in any case to use an explicit transaction.

Not directly related: Your way of "using" the connection is rather strange.

This should work or be "close to working" (I can't test it):

VB
Public Sub Example(connectionString As String) ' add Tireline and selClass as arguments
    Using connection As DB2Connection = New DB2Connection(connectionString)
    Using transaction As DB2Transaction = connection.BeginTransaction(IsolationLevel.Serializable)
    Using command As DB2Command = New DB2Command("", connection, transaction)
		
    connection.Open()

    command.CommandText = "DELETE FROM TESTDATA.VXWFEATURE WHERE I001TRLN=@Tireline AND FECLS=@selClass"
    command.Parameters.Add("@Tireline", iDB2DbType.iDB2VarChar).Value = Tireline
    command.Parameters.Add("@selClass", iDB2DbType.iDB2Decimal).Value = selClass
    command.ExecuteNonQuery()
		
    transaction.Commit()

    End Using
    End Using
    End Using
End Sub


If you can't get this to compile, please tell and I'll try to help.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900