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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trouble converting dataset.table to DAO.recordset

Status
Not open for further replies.

VladimirKim

Programmer
Jan 20, 2005
49
US
Hi, here is the code:
Public Function convertToRS(ByVal ds As DataSet) As Recordset
Dim rs As DAO.Recordset
Dim i, j As Integer
Dim dt As New TableDef
For i = 0 To ds.Tables(0).Columns.Count - 1
dt.CreateField(ds.Tables(0).Columns(i).ColumnName)
Next
For i = 0 To ds.Tables(0).Rows.Count - 1
rs = dt.OpenRecordset()
rs.AddNew()
For j = 0 To ds.Tables(0).Columns.Count - 1
rs(j).Value = ds.Tables(0).Rows(i)(j)
Next
rs.Update()
Next
Return rs
End Function

It gives me an error on rs=dt.OpenRecordset().
It says object invalid or no longer set.
My initial goal to convert dataset into a DAO recordset. There is only one table in the dataset.
 
It could be that I'm doing it completely wrong. Could anybody tell me what's the better way to convert.
Thank you in advance.
 
Thanks for your reply, ca8msm.
But there's gotta be an easier way to do this.
I just need a simple function that takes a single table in the dataset and converts it into a recordset with the same column names.

i'm looking for something like this:

Public Function convertToRS(ByVal ds As DataSet) As DAO.Recordset
Dim rs As DAO.Recordset
...
Return rs
End Function


Thanks again.
 
The only other way I've seen it done is by checking the type of columns in the datatable, converting them to the relevant ADO type and then looping through each row to add it to the recordset. I don't think either method are as simple as you are expecting it to be however, here is an article on this other method:



____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.
 
Thanks ca8msm,
That last link has helped me.
I have added an ADODB library to Access 97 as a reference, so I could use ADO recordsets in addition to DAO.
So, I used that code to pass ADO recordsets across from .NET to Access 97.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top