使用有效(?)SQL创建记录集时,初始EOF值为true [英] Intial EOF value is true when using valid(?) SQL to create recordset

查看:66
本文介绍了使用有效(?)SQL创建记录集时,初始EOF值为true的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿大家非常感谢我在上一篇文章中给予的帮助。


这个我希望对于这里的人们来说很简单

我打开了一条记录设置并且在do循环的开始处开始迭代该集合,EOF值已经是真。所以我的所有代码都被跳过了。我检查本地窗口并通过创建空白查询并将sql粘贴到查询并运行它来测试访问中的sql语句。它工作正常


这是分配给变量的sql语句sqlstr

__________________________________________________ ___

sqlstr =" ; SELECT tblAssoc_edu.ID,tblAssoc_edu.Emp_ID,tblAssoc_edu.degree_id,tblAssoc_edu.degree,tblAssoc_edu.degree_school,tblAssoc_edu.grad_Date,tblAssoc_edu.degree_ma_mi" &安培; _

" FROM tblAssoc_edu" &安培; _

" WHERE(((tblAssoc_edu.degree)像"&安培; CHR $(34)&安培;" *; *"&安培; CHR $(34)&安培;") );"

__________________________________________________ ____________


这是观察窗口和本地窗口中变量的值

__________________________________________________ ____________

" SELECT tblAssoc_edu.ID,tblAssoc_edu.Emp_ID,tblAssoc_edu.degree_id,tblAssoc_edu.degree,tblAssoc_edu.degree_school,tblAssoc_edu.grad_Date,tblAssoc_edu.degree_ma_mi FROM tblAssoc_edu WHERE(((tblAssoc_edu.degree)像" *; *"))"

__________________________________________________ _______


再次直接上面的sql工作,当我粘贴到查询中它返回59行。


现在我用简单的sql语句测试了相同的代码。只需从前一个语句中选择一个字段而不选择where子句就可以了。 sqlstr ="从tblAssoc_edu中选择学位;。 EOF值为false。


注意我按F8并逐步执行代码并检查var值。


我的问题很简单就是简单查询的EOF值为false。直接在[recordset.open sqlstr,cnxn]之后和[do循环]的开头,


但更复杂的一个的EOF值为true。并跳过后续代码。


任何想法???????

解决方案

(34)& " *; *" &安培; Chr


(34)& ");"

__________________________________________________ ____________


这是观察窗口和本地窗口中变量的值

__________________________________________________ ____________

" SELECT tblAssoc_edu.ID,tblAssoc_edu.Emp_ID,tblAssoc_edu.degree_id,tblAssoc_edu.degree,tblAssoc_edu.degree_school,tblAssoc_edu.grad_Date,tblAssoc_edu.degree_ma_mi FROM tblAssoc_edu WHERE(((tblAssoc_edu。学位)喜欢*; *))

__________________________________________________ _______


再次直接上面的sql工作,当我粘贴到它时返回59行查询。


现在我用简单的sql语句测试了相同的代码。只需从前一个语句中选择一个字段而不选择where子句就可以了。 sqlstr ="从tblAssoc_edu中选择学位;。 EOF值为false。


注意我按F8并逐步执行代码并检查var值。


我的问题很简单就是简单查询的EOF值为false。直接在[recordset.open sqlstr,cnxn]之后和[do循环]的开头,


但更复杂的一个的EOF值为true。并跳过后续代码。


任何想法???????


首先,我不认为你给我们看了一个直接的副本/粘贴,因为您在查询结束时错过了分号。 :) Tsk tsk ...


我没有解决方案,但是当你寻找解决方案时可能还有一个解决方法。开始使用MoveFirst怎么样? (也许取决于 RecordCount> 0 )。


另外,你能告诉我们你正在使用什么版本的VB,并发布代码正在执行查询?有时事情可能会有所不同取决于你是否使用ADO或DAO等等。


哦,顺便说一下。只是为了稍微简单的调试,我建议简化查询。访问往往会引入许多不必要的东西,这些东西的使用取决于环境,但会产生很长的SQL。你可以把它修剪成......

SELECT ID,Emp_ID,degree_id,degree,degree_school,grad_Date,degree_ma_mi FROM tblAssoc_edu WHERE degree赞*; *;

Hey everyone many thanks for help with my last post.

This one I hope is an easy one for folks here
I am opened a record set and at the begining of the do loop to begin iterating through the set the EOF value is already "true" so all my code is skipped. I check the local window and tested the sql statement in access by creating a blank query and pasting the sql into the query and running it. It works fine

this is the sql statment being assigned to the variable "sqlstr"
__________________________________________________ ___
sqlstr = "SELECT tblAssoc_edu.ID, tblAssoc_edu.Emp_ID, tblAssoc_edu.degree_id, tblAssoc_edu.degree, tblAssoc_edu.degree_school, tblAssoc_edu.grad_Date, tblAssoc_edu.degree_ma_mi " & _
"FROM tblAssoc_edu " & _
"WHERE (((tblAssoc_edu.degree) Like " & Chr$(34) & "*;*" & Chr$(34) & ")) ;"
__________________________________________________ ____________

this is the value in the variable in the watch window and the local window
__________________________________________________ ____________
"SELECT tblAssoc_edu.ID, tblAssoc_edu.Emp_ID, tblAssoc_edu.degree_id, tblAssoc_edu.degree, tblAssoc_edu.degree_school, tblAssoc_edu.grad_Date, tblAssoc_edu.degree_ma_mi FROM tblAssoc_edu WHERE (((tblAssoc_edu.degree) Like "*;*"))"
__________________________________________________ _______

again the sql directly above works it returns 59 rows when I paste into a query.

Now I have tested the same code with a simple sql statement . By just choosing one field from the previous statement and no where clause and it works e.g. sqlstr = " select degree from tblAssoc_edu;". the EOF value is false.

NOTE I am pressing F8 and stepping through the code and checking the var values as I go.

my problem in short is the simple query has an EOF value of "false" directly after the [recordset.open sqlstr, cnxn] and at the begining of the [do loop] ,

but the more complex one has a EOF value of "true" and the subsequent code is skipped.

Any ideas???????

解决方案

(34) & "*;*" & Chr


(34) & ")) ;"
__________________________________________________ ____________

this is the value in the variable in the watch window and the local window
__________________________________________________ ____________
"SELECT tblAssoc_edu.ID, tblAssoc_edu.Emp_ID, tblAssoc_edu.degree_id, tblAssoc_edu.degree, tblAssoc_edu.degree_school, tblAssoc_edu.grad_Date, tblAssoc_edu.degree_ma_mi FROM tblAssoc_edu WHERE (((tblAssoc_edu.degree) Like "*;*"))"
__________________________________________________ _______

again the sql directly above works it returns 59 rows when I paste into a query.

Now I have tested the same code with a simple sql statement . By just choosing one field from the previous statement and no where clause and it works e.g. sqlstr = " select degree from tblAssoc_edu;". the EOF value is false.

NOTE I am pressing F8 and stepping through the code and checking the var values as I go.

my problem in short is the simple query has an EOF value of "false" directly after the [recordset.open sqlstr, cnxn] and at the begining of the [do loop] ,

but the more complex one has a EOF value of "true" and the subsequent code is skipped.

Any ideas???????


For starters, I don''t think you''re showing us a straight copy/paste there, because you missed the semicolon at the end of the query. :) Tsk tsk...

I don''t have a solution, but perhaps a workaround while you look for one. What about starting out with a MoveFirst? (Perhaps dependent on RecordCount > 0).

Also, can you tell us what version of VB you''re using, and post the code which is executing the query? Sometimes things might work differently depending on whether you''re using ADO or DAO, and so on.

Oh, by the way. Just for slightly simpler debugging, I''d recommend simplifying the query. Access tends to throw in a lot of unnecessary stuff which does have its uses depending on circumstanbces, but makes for very long SQL. You could probably trim it down to...

SELECT ID, Emp_ID, degree_id, degree, degree_school, grad_Date, degree_ma_mi FROM tblAssoc_edu WHERE degree Like "*;*";


这篇关于使用有效(?)SQL创建记录集时,初始EOF值为true的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆