Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GetChunk reset

Status
Not open for further replies.

Glasgow

IS-IT--Management
Jul 30, 2001
1,669
0
0
GB
Is there a way of resetting an ADO field such that the .GetChunk method starts at the beginning of the binary object rather than from where the last GetChunk finished without moving to another record?

Thanks in advance.
 
Try just reading another field and then return again to the field where you want to use the GetChunk on.
 
Thanks Cclint - I really should have read the documentation in more detail (sorry) and I can see that should work.

HOWEVER, in order to do that, I need another field in the same recordset that would 'support' the GetChunk method and I don't have any others with the adFldLong attribute set.

Any other ideas?
 
Then try
Dim rsADO2 As ADODB.Recordset
Set rsADO2 = rsADO.Clone
Debug.Print rsADO2("information").GetChunk(255)
Set rsADO2 = Nothing

'Try Again
Set rsADO2 = rsADO.Clone
Debug.Print rsADO2("information").GetChunk(255)

Set rsADO2 = Nothing
 
Thanks for the further suggestion CCLINT. I am going round in circles and, at the moment it does not even seem to reset when I leave the record and return to it. I must be missing something! I will explore further.
 

Well, a MoveNext/MovePrevious should reset it in any case, as you've mentioned.
Are you resetting the variable which holds the data returned by GetChunk?

sString = sString & rs(0).GetChunk
 
I do accept that common sense and Microsoft documentation suggest that pointer should get reset on MoveNext/MovePrevious but the code below (which fires on a move in the recordset) fails when returning to a record that has already passed through this code once successfully. I am navigating using a datagrid and when I first click on a record with a non-null BLOB, all is OK and code runs through. I can then click on lots of other records with null BLOBs OK (no GetChunk Required) but when I return to the original record, I get 'Invalid use of Null' on the GetChunk line unless I re-instate the commented line that does a GetChunk on a dummy BLOB field (created purely for this purpose!) within the same record. I hope I'm missing something really obvious!


Private Sub rsMain_MoveComplete(ByVal adReason As ADODB.EventReasonEnum, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)

MsgBox "Move to bookmark " & rsMain.Bookmark & " complete"
Dim StrBlob As String, BlkSize As Long, BlobSize As Long
BlkSize = 16384

'Debug.Print IsNull(rsMain!UdrGridDummy.GetChunk(1))
If Not IsNull(rsMain!UdrGridLayout) Then
Do While BlobSize < rsMain!UdrGridLayout.ActualSize
StrBlob = rsMain!UdrGridLayout.GetChunk(BlkSize)
BlobSize = BlobSize + BlkSize
Loop
End If

End Sub
 
I should have said - this code has been trimmed down for the purposes of clarity and narrowing down the problem. Previously it was writing the StrBlob variable to a file.
 
Well, I wish you would have said that at first (Using a Grid)
Because you are using a DataGrid, when you click on a record in the grid, it will retreive all the data for the record (all that is possible)

As you know, a repeated call with GetChunk when all the data has all ready been retrieved produces NULL. And this is what you are doing because the grid has already used it.

You can see this if you do not move to a different record by clicking on the grid, but do so by just calling the MoveNext/MovePrevious. Then the GetChunk works - of course.

You should be adding a vbNullString to the data when assigning it to a string variable anyways:

StrBlob = rsMain!UdrGridLayout.GetChunk(BlkSize) & vbNullString

Also, you shouldn't be adding this field to the grid, if it is large, but create a second rs using a server side cursor, for retrieving this data.
 
The Datagrid does not have a column for this field though it is bound to a recordset which does. Are you saying that the DataGrid (whether it has a column for the BLOB or not) does implicit GetChunks of its own to get all the data? Surely this would suggest that my code would fail EVERY time and not just when I return to the record for the second time?

Yes I have got the GetChunk to work in simpler code and can accept that the DataGrid could be playing a part (sorry I failed to mention it) but I remain confused.

What does the vbnullstring achieve? I thout the getchunk would just return a full buffer or one that is the size of the remaining data, whichever is the smaller?
 
The vbnullstring lets you call the GetChunk with-out having to check if IsNull first.

>The Datagrid does not have a column for this field though it is bound to a recordset which does

Well, again, a lack of info given. Is the column in question at the end of the fields collection?...

Sorry, I'm taking off now.
 
OK understood on vbnullstring, thanks.

Re lack of info - sorry but when you are struggling with a frustrating problem, it's not always easy to see what someone else would deem as relevant!

The field in question is the 7th element of a Fields collection of 14 elements - if that's what you're asking.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top