插入命令在.NET到DB2连接中不起作用

发布于 2025-02-06 03:05:39 字数 3532 浏览 2 评论 0原文

我有一个用vb.net编写的旧应用程序,它使用ODBC连接写入IBM DB2数据库。

它不起作用。

我试图看看值中是否有空间,如果它们不是来自同一类型,两个都是字符串,值是正确的,但是我认为command.executenonquery()返回零的代码>,我收到的消息是,数据库中插入了并非如此。

H始终是,没有例外,只是没有更新。有什么想法吗?

Private Sub Merge(ByVal connectionString As String, ByVal CaseNo As String, ByVal CancelledSurgeryId As String, ByVal ActiveSurgeryId As String, ByVal Cancelled As String, ByVal Active As String, ByVal location As String)

    Using connection As OdbcConnection = New OdbcConnection(connectionString)

        Dim Command As New OdbcCommand()
        Dim transaction As OdbcTransaction
        Command.Connection = connection

        Dim a, b, c, d, e, f, g, h As Integer
        Try
            connection.Open()
            transaction = connection.BeginTransaction()
            Command.Connection = connection
            Command.Transaction = transaction

            Command.CommandText = "Update QS36F.ORPATSURG SET REQSTAT = 'F' WHERE CASENO = ? AND SURGERYID = ?"
            Command.Parameters.Add("@CASENO", Odbc.OdbcType.VarChar).Value = CaseNo
            Command.Parameters.Add("@SURGERID", Odbc.OdbcType.VarChar).Value = CancelledSurgeryId
            a = Command.ExecuteNonQuery()

            Command.CommandText = "delete FROM QS36F.orpctrx WHERE orderno = ? AND CASENO = ? " & _
                        "AND oper IN (SELECT oper FROM QS36F.orpctrx WHERE caseno = ? AND orderno = ?)"

            Command.Parameters.Add("@orderno", Odbc.OdbcType.VarChar).Value = CancelledSurgeryId
            Command.Parameters.Add("@CASENO", Odbc.OdbcType.VarChar).Value = CaseNo
            Command.Parameters.Add("@caseno", Odbc.OdbcType.VarChar).Value = CaseNo
            Command.Parameters.Add("@orderno", Odbc.OdbcType.VarChar).Value = ActiveSurgeryId
            b = Command.ExecuteNonQuery()

            Command.CommandText = "DELETE FROM QS36F.ORPCTRXM WHERE CASENO = ? AND ORDERNO  = ?"
            Command.Parameters.Add("@caseno", Odbc.OdbcType.VarChar).Value = CaseNo
            Command.Parameters.Add("@orderno", Odbc.OdbcType.VarChar).Value = ActiveSurgeryId
            d = Command.ExecuteNonQuery()

                Command.CommandText = "update libor.invtrx set referno = ? , pono  = ? where referno = ? and pono  = ?"
                Command.Parameters.Add("referno", Odbc.OdbcType.VarChar).Value = Active
                Command.Parameters.Add("pono", Odbc.OdbcType.VarChar).Value = ActiveSurgeryId
                Command.Parameters.Add("referno", Odbc.OdbcType.VarChar).Value = Cancelled
                Command.Parameters.Add("pono", Odbc.OdbcType.VarChar).Value = CancelledSurgeryId
                h = Command.ExecuteNonQuery()
       
                transaction.Commit()
                MessageBox.Show("Records successfully written to database.", "Success")
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            Try
                transaction.Rollback()
            Catch
            End Try
        End Try
    End Using
End Sub
This is some sample data for the last one.

|ITEMID|TRXDATE|TRXTYPE|REFERNO        |PONO       |CASENO  |
|------|-------|-------|---------------|-----------|--------|
|00244 |220609 |13     |31215380077    |196474     |01631892|

我在所有查询中都出现了我在评论中发布的内容,但只有这个问题不起作用? 而且它没有更新,有能进吗?


随后是最初的问题,另一个经验丰富的人将其视为:如果我运行查询,则可以正常工作,并且数据库中充满了正确的值。还使用断点搜索

超载分辨率失败了,因为没有可访问的“项目”接受此数量的参数

I have a legacy application written in VB.NET, it uses an ODBC connection to write to an IBM DB2 database.

It is not working.

I've tried to see if there is a space in the values, if they are not from the same type, both are Strings, the values are correct but I think there is a problem in Command.ExecuteNonQuery() which is returning zero and I am getting the message that there was insertion to the database which is not the case.

h is always ZERO, no exceptions are thrown, just no update. Any ideas?

Private Sub Merge(ByVal connectionString As String, ByVal CaseNo As String, ByVal CancelledSurgeryId As String, ByVal ActiveSurgeryId As String, ByVal Cancelled As String, ByVal Active As String, ByVal location As String)

    Using connection As OdbcConnection = New OdbcConnection(connectionString)

        Dim Command As New OdbcCommand()
        Dim transaction As OdbcTransaction
        Command.Connection = connection

        Dim a, b, c, d, e, f, g, h As Integer
        Try
            connection.Open()
            transaction = connection.BeginTransaction()
            Command.Connection = connection
            Command.Transaction = transaction

            Command.CommandText = "Update QS36F.ORPATSURG SET REQSTAT = 'F' WHERE CASENO = ? AND SURGERYID = ?"
            Command.Parameters.Add("@CASENO", Odbc.OdbcType.VarChar).Value = CaseNo
            Command.Parameters.Add("@SURGERID", Odbc.OdbcType.VarChar).Value = CancelledSurgeryId
            a = Command.ExecuteNonQuery()

            Command.CommandText = "delete FROM QS36F.orpctrx WHERE orderno = ? AND CASENO = ? " & _
                        "AND oper IN (SELECT oper FROM QS36F.orpctrx WHERE caseno = ? AND orderno = ?)"

            Command.Parameters.Add("@orderno", Odbc.OdbcType.VarChar).Value = CancelledSurgeryId
            Command.Parameters.Add("@CASENO", Odbc.OdbcType.VarChar).Value = CaseNo
            Command.Parameters.Add("@caseno", Odbc.OdbcType.VarChar).Value = CaseNo
            Command.Parameters.Add("@orderno", Odbc.OdbcType.VarChar).Value = ActiveSurgeryId
            b = Command.ExecuteNonQuery()

            Command.CommandText = "DELETE FROM QS36F.ORPCTRXM WHERE CASENO = ? AND ORDERNO  = ?"
            Command.Parameters.Add("@caseno", Odbc.OdbcType.VarChar).Value = CaseNo
            Command.Parameters.Add("@orderno", Odbc.OdbcType.VarChar).Value = ActiveSurgeryId
            d = Command.ExecuteNonQuery()

                Command.CommandText = "update libor.invtrx set referno = ? , pono  = ? where referno = ? and pono  = ?"
                Command.Parameters.Add("referno", Odbc.OdbcType.VarChar).Value = Active
                Command.Parameters.Add("pono", Odbc.OdbcType.VarChar).Value = ActiveSurgeryId
                Command.Parameters.Add("referno", Odbc.OdbcType.VarChar).Value = Cancelled
                Command.Parameters.Add("pono", Odbc.OdbcType.VarChar).Value = CancelledSurgeryId
                h = Command.ExecuteNonQuery()
       
                transaction.Commit()
                MessageBox.Show("Records successfully written to database.", "Success")
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            Try
                transaction.Rollback()
            Catch
            End Try
        End Try
    End Using
End Sub
This is some sample data for the last one.

|ITEMID|TRXDATE|TRXTYPE|REFERNO        |PONO       |CASENO  |
|------|-------|-------|---------------|-----------|--------|
|00244 |220609 |13     |31215380077    |196474     |01631892|

The thing I posted in my comments is present on all query, yet only this one is not working?
And it is not getting updated, any workarounds?


Subsequently to the initial question, another experienced person gave it a look: if I run the query, it works and the database is filled with the correct values. Also searching using breakpoints is giving

Overload resolution failed because no accessible 'Item' accepts this number of arguments

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

李白 2025-02-13 03:05:39

该解决方案是使用command.parameters.clear()清除查询之间的参数。

The solution was clearing the parameters between queries using Command.Parameters.Clear().

献世佛 2025-02-13 03:05:39

如果executenonquery返回零,则意味着操作是成功的,但没有修改记录,这意味着数据库不包含与您的White子句匹配的任何记录。您发布的代码完全没有错,问题纯粹与数据有关,数据您没有向我们展示,而且显然没有看过。

If ExecuteNonQuery returns zero then that means that the operation was successful but no records were modified, which means that the database doesn't contain any records that match your WHERE clause. There is nothing at all wrong with the code you posted and the issue is purely related to the data, which you didn't show us and, apparently, didn't even look at.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文