【问题标题】:How to display message if SQL query returns nothing or times out in VB6如果 SQL 查询在 VB6 中不返回任何内容或超时,如何显示消息
【发布时间】:2013-07-16 14:53:44
【问题描述】:

我有一个旧的 VB6 应用程序,我必须优化查询运行时间。我成功地做到了,但我想添加一个字段以在查询不返回任何内容或查询超时时显示消息。
您可以发布链接或显示一些可以提供帮助的示例代码吗?我几乎没有 VB6 或 ADO 的经验,所以任何帮助或指导将不胜感激。

这是执行查询的代码。

'Execute the query.
If ADOConnect(moConn, moParms) Then
    Set moRS = moConn.Execute(sSql)
End If

这是我到目前为止的想法。

'Test if results are null
If IsNull(sSql) Then
    MsgBox "null"

谢谢

【问题讨论】:

标签: vb6


【解决方案1】:

怎么样

moConn.ConnectionTimeout = 300
If ADOConnect(moConn, moParms) Then
    Set moRS = moConn.Execute(sSql)
End If

If moRS.RecordCount = 0 Then
    MsgBox "no record"

【讨论】:

  • 超时消息是否为:If moConn.ConnectionTime = true Then MsgBox "Query Timed Out"?
  • 为什么要显示消息而不是避免超时?
  • 如果避免超时,查询不会停止运行吗?如果查询未完成,我希望向用户显示一条消息
  • 如果没有超时,为什么查询会停止?查询完成后将停止...
  • 我是说如果查询由于超时而停止,我希望向用户显示一条消息,而不是仅仅停止应用程序并让用户想知道发生了什么。
【解决方案2】:
If moRS.EOF then
    MsgBox "null"
End If

循环遍历它:

Do While Not moRS.EOF
   dim colA = moRS("colA")
   moRs.MoveNext()
Loop

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-25
    • 2012-07-17
    • 1970-01-01
    相关资源
    最近更新 更多