473,422 Members | 1,894 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,422 software developers and data experts.

Order of retrieving fields from SQL?

!NoItAll
297 100+
I am retrieving data from an MS SQL database using SQL2000 on Windows XP. I am using VB6.
I am having a very odd problem with certain fields returning empty - when they are not.
Here is my code:

My Select statement is
Expand|Select|Wrap|Line Numbers
  1. Select id1, id2, id8, id14, id35, id38, id186, id5000, id5004 From header_record where record_id=346621
  2.  
I then use the following code to assign the values into variables

Expand|Select|Wrap|Line Numbers
  1. Do While (rsObjectSet.BOF = False) And (rsObjectSet.EOF = False)
  2.         dArcDate = ConvertToDate(Byte2Char(rsObjectSet.Fields("id1") & ""))
  3.         dModDate = ConvertToDate(Byte2Char(rsObjectSet.Fields("id2") & ""))
  4.         sAuthor = rsObjectSet.Fields("id186") & ""
  5.         sSlug = rsObjectSet.Fields("id8") & ""
  6.         sBody = rsObjectSet.Fields("id14") & ""
  7.         sTimeCode = ConvertToHMS(Byte2Char(rsObjectSet.Fields("id35") & ""))
  8.         sTapeLen = ConvertToHMS(Byte2Char(rsObjectSet.Fields("id38") & ""))
  9.         sModby = rsObjectSet.Fields("id5000") & ""
  10.         sTape = rsObjectSet.Fields("id5004") & ""
  11. Loop
  12.  
This code calls some functions (ConvertToDate, ConvertToHMS and Byte2Char) that are not really material to my problem...
But here is my problem - depending on the order in which I read the columns - certain columns will return empty - when there is data there! If I rearrange the order in which I execute these statements then different columns will return blank.
For example: in the code above I fill the values of sSlug and sBody, calling for sSlug first.
Expand|Select|Wrap|Line Numbers
  1.         sSlug = rsObjectSet.Fields("id8") & ""
  2.         sBody = rsObjectSet.Fields("id14") & ""
  3.  
With it that way then column id14 will return empty. If I simply reverse the order
Expand|Select|Wrap|Line Numbers
  1.         sBody = rsObjectSet.Fields("id14") & ""
  2.         sSlug = rsObjectSet.Fields("id8") & ""
  3.  
Then column id8 will return empty

Can anyone tell me what I am doing wrong?
Oct 17 '10 #1
8 1722
gpl
152 100+
Im not sure if this is relevant, but you do not have a movefirst call before your loop that builds up the values .. neither do you have a movenext at the bottom of the loop

My memories of using recordsets was that a movefirst was necessary before checking the eof/bof (and being booleans, you dont need to check for being equal to false, this would do
Expand|Select|Wrap|Line Numbers
  1. Do While (Not (rsObjectSet.BOF or rsObjectSet.EOF))
Oct 17 '10 #2
!NoItAll
297 100+
You are correct - I simply left that out for brevity - I probably should have left the loop part out too. I do have a movefirst just before the loop and a movenext at the bottom (inside) the loop.
I don't believe the movefirst is strictly necessary - but it's there none-the-less.

I like your loop test - it's much more elegant! Thanks!

Des
Oct 17 '10 #3
gpl
152 100+
This is bizarre behaviour, to say the least
I found this on experts-exchange *** Snip - Sorry but it's not ***
-- hope its ok to post external urls, but wanted it properly credited
Graham

quote:
Make sure the cursor type for the recordset is not forward only; use adOpenStatic:

rs.CursorType = adOpenStatic

If you don't have a constant defined for adOpenStatic, use the value instead, which is 3:

rs.CursorType = 3

I have had recordsets doing weird stuff when they're forward only, because you read the last field in the record and then can't go back and read an earlier field in the same record. I'm fairly sure, going from memory, that it didn't error, it just didn't get the correct value. Let me know if this helps...

Flynnious
/quote
Oct 17 '10 #4
!NoItAll
297 100+
Thanks - this appear to not be the source of my issue. I do use adOpenForwardOnly but am aware I can only read the fields once. I do move everything into a structure from each field and work with the data from that structure. I did try adOpenStatic - but it was so slow I deemed it unusable. With forward only it only takes a few seconds to run the Select, with OpenStatic I gave up after an hour and a half...
Oct 19 '10 #5
ck9663
2,878 Expert 2GB
I think this is more of a VB6 issue than a sql-server issue...

Good Luck!!!

~~ CK
Oct 19 '10 #6
NeoPa
32,556 Expert Mod 16PB
If the ForwardOnly open works much quicker for you, then why not consider working with it more closely. Find the order the fields are processed in, then access them in that order. That way you get the speed and the reliability.
Oct 20 '10 #7
!NoItAll
297 100+
Thanks NeoPa - I think you may be putting me on the right track...

So when I create a select statement such as

Expand|Select|Wrap|Line Numbers
  1. select obje_id, obje_date, obje_text, obje_author, obje_appr from header_record where obje_type=2
Does that not also define the order in which I should access the fields? If not - is there a method to determine the processing order?
Oct 20 '10 #8
NeoPa
32,556 Expert Mod 16PB
Possibly. I'm afraid I don't know that well enough to say.

What I can say though, is that a SELECT * should get all fields available without compromising any. From there, I would guess that the order the fields are defined in the record would be a good starting approach (for transferring the data to your variables). If that doesn't work first time, then try reversing it. Otherwise, trial and error is all I have, but there may be something else out there with more info on the matter. I've never come across this problem before. I'm just working deductively from what I do know.
Oct 20 '10 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Tim Chmielewski | last post by:
For an auto-generated form I have the following order of fields: savevalues userid productcode PrintColour1_1 Colour1_1 Quantity_1 " " " " " " " ...
0
by: Maciej Zoltowski | last post by:
Hi, I've got a following problem with the order of fields in extended element: let's assume, that I have a complex type with a few fields, that I want to extend with additional field. In...
3
by: D. Stimits | last post by:
I'm not looking for an exact answer here, but instead something more "rule of thumb". If I have a table with many fields, and I retrieving small groups of fields during a SELECT, whereby the groups...
1
by: Ralph | last post by:
Hello I am using the report wizard in A2K to print 4 fields with my table as my data source. I would like the order of the fields to stay the same a; b; c; and d. When I make "print 1" and sort on...
4
by: Joe User | last post by:
Hi all....I have a feeling this is going to be one of those twisted query questions, but here it goes anyways.... I want to generate a report that shows the chronology of events (represented by...
0
by: cjbland | last post by:
First off I apologize if this has been discussed before, I'm not certain how to search for what I'm looking for so I figured I'd throw this out there and see what I got. I am working with a...
6
by: Duderino82 | last post by:
I was wondering if there is a way to collect the names of the fields from a specific table. I think the soluction is to be researched in the sql code but maybe someone knows of a way to o so...
1
by: Phil Galey | last post by:
I'm using XMLSerializer in VB.NET to serialize class-based objects to XML. It's serializing fine, except that I don't seem to have control over the order in which the various fields (properties) of...
1
by: abar | last post by:
I just want to display the selected or specified fields when i specify the start and end date in a year CAN YOU HELP ME OUT??????????????
0
by: ady189 | last post by:
Does anyone know of an SQL statement that i can use to change the order that a field appears in a table? For example i have a table called entry with several fields in it. The 2 that i want to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.