从阅读器循环查询数据库时遇到问题:
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循环时,我必须从新查询到数据库获得整数firstfree 通过在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
答案 0 :(得分:0)
我看不出你的语言是什么,等等。但在你看来,你的循环中有两个明显的拼写错误。
例如,应该:
End Using ''cmd
是
End Using ''icmd
并且应该
End Using ''reader
是
End Using ''reader1
无论如何,这看起来像循环语法问题,所以我将调试视为.net问题而不是PostgreSQL问题。