我有这段代码没有从 datareader 填充组合框。我做了各种检查,确认数据库正在连接,查询也正确。Databaseconnections 是一个模块,我在其中声明了所有变量,包括连接字符串和数据读取器(Public dr As SqlDataReader)。调试时一切都很顺利,但是当我点击 While 循环时,它会跳到循环的末尾而没有任何错误。我无法理解遗漏了什么。请帮忙。
Public Sub loadLocatns()
Try
Openconn()
cmd.CommandText = "SELECT distinct jobs.[file] FROM [BERVSDB].[dbo].[jobQueue] as jobs where (jobs.form_status<>'c') and (jobs.CI = '" & Ccode & "') and (jobs.[file] in( SELECT dts.[file] from [BERVSDB].[dbo].[master] as dts where (dts.[status] is null) or (dts.[status] <> 'X') ))"
cmd.Connection = conn
Databaseconnections.dr = cmd.ExecuteReader()
If IsNothing(dr) Then
MessageBox.Show("No Data found")
Else
If dr.Read() Then
While dr.Read
Me.ComboBox1.Items.Add(dr(0))
End While
Else
MessageBox.Show("Not reading!")
End If
dr.Close()
conn.Close()
End If
Catch ex As Exception
MessageBox.Show("Error:" & ex.Message)
End Try
End Sub