J
Jamal Samedov
Hi,
I have an issue with filling datatables from ADO.Recordset.
May be somebody had an experience or clue with this behavior, please, share
your knowledge
Problem is following:
Ado.Recordset is opened from a table in MS SQL 2005 database and queried
from they: namely it is opened one of the tables with following attributes:
pRecordset = New ADODB.Recordset()
pRecordset.CursorLocation = CursorLocationEnum.adUseClient
pRecordset.CursorType = CursorTypeEnum.adOpenStatic
pRecordset.LockType = LockTypeEnum.adLockOptimistic
pRecordset.ActiveConnection = mConnection
pRecordset.Open(pTableName)
locResult = pRecordset.State = ObjectStateEnum.adStateOpen
then I fill a table with following procedure:
Friend Sub FillTable(ByRef pTable As DataTable, ByVal pRecordset As
ADODB.Recordset)
Dim locAdapter As OleDbDataAdapter
Try
locAdapter = New OleDbDataAdapter
pTable = New DataTable
pTable.TableName = pRecordset.Source.ToString
locAdapter.Fill(pTable, pRecordset)
Catch ex As Exception
LogErrorMessage("Unexpected error", ex)
End Try
End Sub
This works fine, however if I call the same procedure second type it does
not fill table without Requery
First call gives filled table and second time table is empty. Call is like
this:
FillTable(mTable, mRecordset)
FillTable(mTable, mRecordset)
If I put bitween the calls additional line:
mRecordset.Requery then in both calls tables are filled with data.
With ado.recordset is nothing happend in debug time I see that there is the
same amount of records. I thought may be cursor in recordset can move only
in one direction, but this is not a case. I have chacked this with methods
of ado.recordset like MoveFirst, MoveNext and see that the current record is
changing. However if I put between calls
mRecordset.MoveFirst it does not help.
I just do not like every time request data from database.
Any ideas are appreciated.
Regards,
I have an issue with filling datatables from ADO.Recordset.
May be somebody had an experience or clue with this behavior, please, share
your knowledge
Problem is following:
Ado.Recordset is opened from a table in MS SQL 2005 database and queried
from they: namely it is opened one of the tables with following attributes:
pRecordset = New ADODB.Recordset()
pRecordset.CursorLocation = CursorLocationEnum.adUseClient
pRecordset.CursorType = CursorTypeEnum.adOpenStatic
pRecordset.LockType = LockTypeEnum.adLockOptimistic
pRecordset.ActiveConnection = mConnection
pRecordset.Open(pTableName)
locResult = pRecordset.State = ObjectStateEnum.adStateOpen
then I fill a table with following procedure:
Friend Sub FillTable(ByRef pTable As DataTable, ByVal pRecordset As
ADODB.Recordset)
Dim locAdapter As OleDbDataAdapter
Try
locAdapter = New OleDbDataAdapter
pTable = New DataTable
pTable.TableName = pRecordset.Source.ToString
locAdapter.Fill(pTable, pRecordset)
Catch ex As Exception
LogErrorMessage("Unexpected error", ex)
End Try
End Sub
This works fine, however if I call the same procedure second type it does
not fill table without Requery
First call gives filled table and second time table is empty. Call is like
this:
FillTable(mTable, mRecordset)
FillTable(mTable, mRecordset)
If I put bitween the calls additional line:
mRecordset.Requery then in both calls tables are filled with data.
With ado.recordset is nothing happend in debug time I see that there is the
same amount of records. I thought may be cursor in recordset can move only
in one direction, but this is not a case. I have chacked this with methods
of ado.recordset like MoveFirst, MoveNext and see that the current record is
changing. However if I put between calls
mRecordset.MoveFirst it does not help.
I just do not like every time request data from database.
Any ideas are appreciated.
Regards,