执行删除语句但不从数据库中删除数据 [英] Delete statement executes but Data is not deleted from Database

查看:131
本文介绍了执行删除语句但不从数据库中删除数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Experts,



我有一个Windows窗体应用程序。我正在使用我的DB2数据库连接,这是我的代码。代码执行没有任何错误。但是当我在数据库中看到时,我仍然可以看到声称被删除的记录。意思是它没有删除。



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.

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?

推荐答案

有两个可能的原因:



1)您提供给WHERE子句的值实际上并不匹配任何记录。 />


2)DB2可能需要提交显式事务才能不回滚DELETE语句。我实际上不知道是不是这种情况 - 但在任何情况下使用明确的交易都是好的做法。



不直接相关:你的方式使用连接相当奇怪。



这应该工作或接近工作(我无法测试):



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):

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.


这篇关于执行删除语句但不从数据库中删除数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆