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

Re: Converting Recordset to DataView by Miha

Miha
Tue Jan 20 12:45:03 CST 2004

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.

--
Miha Markic - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

"kjvt" <doindotnet@excite.com> wrote in message
news:70qq009k5ff7i5t3i0t0lm6q9o9tbejtfo@4ax.com...
> 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



Re: Converting Recordset to DataView by kjvt

kjvt
Tue Jan 20 13:14:24 CST 2004

Miha,

Thanks for your response. See below:

Kees

On Tue, 20 Jan 2004 19:45:03 +0100, "Miha Markic" <miha at rthand com>
wrote:

>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.