0

我从阅读器循环中查询数据库时遇到问题:

    Using cn As NpgsqlConnection = getConnection()
        Using t As NpgsqlTransaction = cn.BeginTransaction()
           Using cmd As New NpgsqlCommand("SELECT tab_id, i1, d1, rez1, b FROM " & myfirstTable & " WHERE bdoc='" & bdoc.ToString & "' ORDER BY b", cn)
                Using reader1 As NpgsqlDataReader = cmd.ExecuteReader()

    --------------> ''GOES HERE
    |               While (reader1.Read())
    |                   Dim sifra As Integer = CInt(reader1("sifra"))
    | 
    |                       Using icmd As New NpgsqlCommand("SELECT dtbl_id FROM " & mysecondTable & " WHERE dtbl_id>" & firstfree.ToString & " AND kni::int=0 ORDER BY dtbl_id LIMIT 1", cn)
    |               
    --------------------------- ''FROM HERE
                                firstfree = CInt(icmd.ExecuteScalar())
                            End Using ''cmd

                    End While
                End Using ''reader
            End Using ''cmd
            t.Commit()
        End Using
    End Using

虽然 reader's.read 循环我必须先从新查询到数据库中获取整数。
通过在 pgAdmin 中进行测试,我的命令工作很好。
但在显示的程序中没有。
当 firstfree = CInt(icmd.ExecuteScalar()) 将被执行时 ''FROM HERE 程序跳转到新的循环步骤 ''GOES HERE

这里有什么明显不正确的地方吗?如何让它发挥作用?

这是getConnection函数。

Public Function getConnection() As NpgsqlConnection

    Dim chkCon As New NpgsqlConnection(String.Format( _
                      "Server={0};Port={1};User Id={2};Password={3};Database={4};Preload Reader = true;", _
                      dbServer, dbPort, dbUser, dbPass, mydatabase))
    Try
        chkCon.Open()
    Catch ex As Exception
        Return Nothing
    End Try

    Return chkCon
End Function
4

1 回答 1

0

我看不到您的语言是什么,等等,但在我看来,您的循环中有两个明显的拼写错误。

例如,应该:

 End Using ''cmd

 End Using ''icmd

并且应该

 End Using ''reader

 End Using ''reader1

无论如何,这看起来像是一个循环语法问题,所以我会将调试视为 .net 问题而不是 PostgreSQL 问题。

于 2013-12-06T06:12:01.717 回答