简体   繁体   English

使用vb6从数据库查询数据以及使用adodb查询ms访问

[英]Querying data from database with vb6 and ms access with adodb

I want to select and view my data in the database, but it's proving to be a challenge. 我想选择并查看数据库中的数据,但是事实证明这是一个挑战。 Any advice on where I could be missing it? 关于我可能会错过的任何建议? If I run this code even when the select criteria is met, it always returns search failed. 如果即使满足选择条件,我也运行此代码,它将始终返回搜索失败。 Any help? 有什么帮助吗?

If txtSun.Text = "SUN" Then
    Set rst = New ADODB.Recordset
    Dim sSql As String
    sSql = "SELECT * FROM SundryProduct WHERE ProdCont='" & txt_con_code.Text & "'"
    rst.Open sSql, Cnn, adOpenForwardOnly, , adCmdText
    'rst.Open "SELECT * FROM SundryProduct WHERE ProdCont='" & txt_con_code.Text & "' ", Cnn, adOpenForwardOnly, , adCmdText
    If rst.EOF Then
    MsgBox ("SEARCH FAILED")
    Else
    MsgBox ("QUANTITY ORDERED  " & rst!QuantityOrdered & vbCrLf & "   My Load Number is   " & rst!LoadNumber)
    End If
End If

I am trying to find out if there is a record with a matching ProdCont value in the database, but since I was still trying to make this code work in the first place I have only put messageboxes in the code. 我试图找出数据库中是否存在具有匹配ProdCont值的记录,但是由于我仍然试图首先使该代码正常工作,因此我仅在代码中放入了消息框。 I have even tried putting in an actual value that I know exists in the database but it still returns the search failed messagebox even though I know the value exists in the database. 我什至尝试输入数据库中已知的实际值,但是即使我知道数据库中存在该值,它仍会返回搜索失败的消息框。

If rst.EOF = True Then '----> here
  MsgBox ("SEARCH FAILED")
Else
  MsgBox ("QUANTITY ORDERED  " & rst!QuantityOrdered & vbCrLf & "   My Load Number is   " &  rst!LoadNumber)
End If

What happens is you try to just run a simple query ie select * from SundryProduct? 您尝试运行一个简单的查询(即从SundryProduct中选择*)会发生什么? I would start with that and build on it to eliminate the possibilty of coding/syntax causing the error message 我将从此开始并在此基础上消除引起错误消息的编码/语法的可能性

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM