|
-
Apr 27th, 2004, 12:59 PM
#1
Thread Starter
Hyperactive Member
ADO Recordset returning blank fields *RESOLVED*
Hey everyone,
I've got the following code:
Code:
Set rsMyRS = cn.execute("SELECT * FROM INDEX")
Do until rsMyRS.EOF
Debug.Print(rsMyRs.Fields(26).Value)
rsMyRS.MoveNext
Loop
Where cn is a connection to an SQL Server running on my computer.
The problem is that this prints out a blank, even though I can go look at the table in Ent. Manager and see that the field has a value in it. After I play around with the recordset object in the Debug window, sometimes I can get it to display the real value, but not always.
Anyone know why it would return a blank? It's not even returning NULL, but just a blank string.
Thanks!
Last edited by BenFinkel; Apr 29th, 2004 at 10:07 AM.
-
Apr 27th, 2004, 02:48 PM
#2
If you're only looking for Fields(26).Value 9whatever that field is) then simply specify its name in the select instead:
VB Code:
Set rsMyRS = cn.execute("SELECT SomeField FROM INDEX")
Do until rsMyRS.EOF
Debug.Print "" & rsMyRs!SomeField 'or use IsNull() to handle nulls
rsMyRS.MoveNext
Loop
Note: personally, I never use syntax such Fields(Index) as it's too easy to be off and get wrong results.
-
Apr 27th, 2004, 09:42 PM
#3
Also, change the table name from INDEX to something else. Its
not good programming to name user defied objects the same
name as system objects.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Apr 28th, 2004, 10:11 AM
#4
Hyperactive Member
maybe if you set the CursorLocation to "your side"
VB Code:
rsMyRS.CursorLocation = adUseClient 'Set the cursor to your side
Set rsMyRS = cn.execute("SELECT * FROM INDEX")
Do until rsMyRS.EOF
Debug.Print(rsMyRs.Fields(26).Value)
rsMyRS.MoveNext
Loop
"Who Dares Wins" - "Quien se Arriesga Gana"
Mail me at: 
-
Apr 28th, 2004, 10:41 AM
#5
Fanatic Member
Yeah I fixed this type of problem messing with the cursor location of the connection object as well - although in my case - switching to server side did the trick. Maybe play around with that a bit.
"Knowledge is gained when different people look at the same information in different ways"
- Louis Pasteur
-
Apr 29th, 2004, 10:06 AM
#6
Thread Starter
Hyperactive Member
Robdog, Rhinobull,
The example I gave was a trimmed down version of the code that explicitly showed the error I was receiving. My table isn't really named INDEX and I'm not really using the field index to reference the field. I was looking for some information that pertained specifically to the field returning blank data when I knew for a fact that there was data in it.
*RESOLUTION*
Turns out what I needed to do (and this may relate to the Cursor location) was use the Recordset.Open method instead of the Connection.Execute method and it worked find. It also runs much more quickly, so I'm assuming that the Open method somehow loads the data locally while the Execute method continually re-connects to the database.
--Ben
-
Apr 29th, 2004, 12:51 PM
#7
Fanatic Member
Indeed, the open method places the cursor location (server side I believe) differently than the execute method which if memory serves puts the cursor client side (might be the other way around - my dislexia aside!! )
"Knowledge is gained when different people look at the same information in different ways"
- Louis Pasteur
-
Apr 29th, 2004, 04:03 PM
#8
Despite the obvious difference - location of your cursor has nothing to do with reading data from field as long as field name (or index) is correct.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|