Converting Recordset to DataView

K

kjvt

I originally posted this question to the vb.net newsgroup, but it was
suggested that I re-post here.

I have an application that was converted from VB6 to .Net. The app
uses a data access layer that returns data as disconnected recordsets.
I'm adding new functionality to the app and want to use .Net controls
and data binding. So, I'm converting a recordset to a dataview that
can be bound to a listbox control. I'm doing this conversion via a
data adapter using the following code:

Public Shared Function GetViewFromRS(ByVal pRS As ADODB.Recordset) _
As DataView

Dim sAdapter As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter
Dim sTable As System.Data.DataTable = New DataTable

sAdapter.Fill(sTable, pRS)

GetViewFromRS = New DataView(sTable)

End Function

So far so good. The first time I call this function it works
perfectly. However, I need to call it multiple times to update the
DataView as the recordset is modified. The problem is that subsequent
calls to this function for the same recordset always return a DataView
that has no rows (Count = 0).

Can anyone explain why this problem is occuring and how I might work
around it?

Thank you.

Kees VanTilburg
VanTilburg Enterprises
 
M

Miha Markic

Hi kjvt,

I guess the problem lies in Fill method (check if sTable has records the
second time).
Also, try calling pRs.MoveFirst (if not pRs.EOF) before Fill.
 
K

kjvt

Miha,

Thanks for your response. See below:

Kees

Hi kjvt,

I guess the problem lies in Fill method (check if sTable has records the
second time).

Yes, you are correct, the rows collection for sTable is empty on the
second call.
Also, try calling pRs.MoveFirst (if not pRs.EOF) before Fill.

I have tried this, but no improvement. I also tried cloning the
recordset prior to calling the Fill method, in case the recordset was
being modified somehow by Fill. And, I tried persisting the DataTable
in memory and calling sTable.Clear prior to Fill.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top