Unable to cast COM object of type 'ADODB.RecordsetClass' to classtype 'System.Object[]'

M

matthieu.sarthou

Hi everyone,

I am using Visual Basic 2005. My project is in vb.net.
After executing a request on an Access Table, I would like to copy my
recordset into an array as such:

Dim ConnectionString As String = "Provider=Microsoft.Jet.OLEDB.
4.0; Data Source=c:\myDataBase.mdb"
Dim sql As String = "SELECT * FROM [myTable];"
Dim conn1 As ADODB.Connection = New ADODB.Connection
conn1.Open(ConnectionString)
Dim rs As New ADODB.Recordset
rs = conn1.Execute(sql)
Dim tmp() as object = rs

The error message I get is:

Unable to cast COM object of type 'ADODB.RecordsetClass' to class type
'System.Object[]'. Instances of types that represent COM components
cannot be cast to types that do not represent COM components; however
they can be cast to interfaces as long as the underlying COM component
supports QueryInterface calls for the IID of the interface.

Does anyone know why I am not allowed to perform this operation ?
 
M

Mr. Arnold

Hi everyone,

I am using Visual Basic 2005. My project is in vb.net.
After executing a request on an Access Table, I would like to copy my
recordset into an array as such:

Dim ConnectionString As String = "Provider=Microsoft.Jet.OLEDB.
4.0; Data Source=c:\myDataBase.mdb"
Dim sql As String = "SELECT * FROM [myTable];"
Dim conn1 As ADODB.Connection = New ADODB.Connection
conn1.Open(ConnectionString)
Dim rs As New ADODB.Recordset
rs = conn1.Execute(sql)
Dim tmp() as object = rs

The error message I get is:

Unable to cast COM object of type 'ADODB.RecordsetClass' to class type
'System.Object[]'. Instances of types that represent COM components
cannot be cast to types that do not represent COM components; however
they can be cast to interfaces as long as the underlying COM component
supports QueryInterface calls for the IID of the interface.

Does anyone know why I am not allowed to perform this operation ?


Apparently you can't do that below.

Dim tmp() as object = rs

rs (ADODB.RecordsetClass) a COM component cannot become/cast to a tmp()
array (System.Object[] -- [] means array).

You're going to have to read the recordset manually to load each record into
the array maybe making object out of each record in the rs and loading an
object that represents the data of each record into the array.
 
M

Michel Posseth [MCP]

I have not checked this but in theory you should be able to do this

Dim ConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=c:\myDataBase.mdb"
Dim sql As String = "SELECT * FROM [myTable];"
Dim conn1 As ADODB.Connection = New ADODB.Connection
conn1.Open(ConnectionString)
Dim rs As New ADODB.Recordset
rs = conn1.Execute(sql)
Dim tmp() as object = rs.Getrows


the getrows method returns the recordset in a array ofcourse the array has 2
dimensions
the first argument specifies the FieldIndex and the second one specifies the
RecordIndex

For iRecord = 0 To UBound(tmp, 2) 'loop through the records
'tmp(fieldnumber, record )= value of field debubug.writeline (tmp(0,
irecord )) 'so this writes the first field of all records Next HTH

Michel Posseth [MCP]
 
S

Scotty

Hi everyone,
I am using Visual Basic 2005. My project is in vb.net.
After executing a request on an Access Table, I would like to copy my
recordset into an array as such:
Dim ConnectionString As String = "Provider=Microsoft.Jet.OLEDB.
4.0; Data Source=c:\myDataBase.mdb"
Dim sql As String = "SELECT * FROM [myTable];"
Dim conn1 As ADODB.Connection = New ADODB.Connection
conn1.Open(ConnectionString)
Dim rs As New ADODB.Recordset
rs = conn1.Execute(sql)
Dim tmp() as object = rs
The error message I get is:
Unable to cast COM object of type 'ADODB.RecordsetClass' to class type
'System.Object[]'. Instances of types that represent COM components
cannot be cast to types that do not represent COM components; however
they can be cast to interfaces as long as the underlying COM component
supports QueryInterface calls for the IID of the interface.
Does anyone know why I am not allowed to perform this operation ?

Apparently you can't do that below.

Dim tmp() as object = rs

rs (ADODB.RecordsetClass) a COM component cannot become/cast to a tmp()
array (System.Object[] -- [] means array).

You're going to have to read the recordset manually to load each record into
the array maybe making object out of each record in the rs and loading an
object that represents the data of each record into the array.

Hi, thank you for helping me.

Here is the thing: when I do this

Dim Array() As Object = {ObjetDataSet1.Tables(0)}

the operation takes less than a second. It would be really great if
there was a way to do the same thing with a recordset (Dim array() as
object = rs). Maybe with a special kind of array ?
If I want to load each record in my array, it is gonna take more than
a minute, as my rs has more than 160000 records.

Any suggestion wil be greatly appreciated !
 
M

Mr. Arnold

Hi everyone,
I am using Visual Basic 2005. My project is in vb.net.
After executing a request on an Access Table, I would like to copy my
recordset into an array as such:
Dim ConnectionString As String = "Provider=Microsoft.Jet.OLEDB.
4.0; Data Source=c:\myDataBase.mdb"
Dim sql As String = "SELECT * FROM [myTable];"
Dim conn1 As ADODB.Connection = New ADODB.Connection
conn1.Open(ConnectionString)
Dim rs As New ADODB.Recordset
rs = conn1.Execute(sql)
Dim tmp() as object = rs
The error message I get is:
Unable to cast COM object of type 'ADODB.RecordsetClass' to class type
'System.Object[]'. Instances of types that represent COM components
cannot be cast to types that do not represent COM components; however
they can be cast to interfaces as long as the underlying COM component
supports QueryInterface calls for the IID of the interface.
Does anyone know why I am not allowed to perform this operation ?

Apparently you can't do that below.

Dim tmp() as object = rs

rs (ADODB.RecordsetClass) a COM component cannot become/cast to a tmp()
array (System.Object[] -- [] means array).

You're going to have to read the recordset manually to load each record
into
the array maybe making object out of each record in the rs and loading an
object that represents the data of each record into the array.

Hi, thank you for helping me.

Here is the thing: when I do this

Dim Array() As Object = {ObjetDataSet1.Tables(0)}

the operation takes less than a second. It would be really great if
there was a way to do the same thing with a recordset (Dim array() as
object = rs). Maybe with a special kind of array ?
If I want to load each record in my array, it is gonna take more than
a minute, as my rs has more than 160000 records.

Any suggestion wil be greatly appreciated !
 
S

Steve Gerrard

Scotty said:
Here is the thing: when I do this

Dim Array() As Object = {ObjetDataSet1.Tables(0)}

the operation takes less than a second. It would be really great if
there was a way to do the same thing with a recordset (Dim array() as
object = rs). Maybe with a special kind of array ?
If I want to load each record in my array, it is gonna take more than
a minute, as my rs has more than 160000 records.

Any suggestion wil be greatly appreciated !

Um, how about using ADO.Net instead? You obviously like the results that gives
you. Why do have to use ADODB?
 
S

Scotty

news:54471eaf-abf0-4046-9532-4b0b2432c7b7@m23g2000hsc.googlegroups.com...
Hi everyone,
I am using Visual Basic 2005. My project is in vb.net.
After executing a request on an Access Table, I would like to copy my
recordset into an array as such:
Dim ConnectionString As String = "Provider=Microsoft.Jet.OLEDB.
4.0; Data Source=c:\myDataBase.mdb"
Dim sql As String = "SELECT * FROM [myTable];"
Dim conn1 As ADODB.Connection = New ADODB.Connection
conn1.Open(ConnectionString)
Dim rs As New ADODB.Recordset
rs = conn1.Execute(sql)
Dim tmp() as object = rs
The error message I get is:
Unable to cast COM object of type 'ADODB.RecordsetClass' to class type
'System.Object[]'. Instances of types that represent COM components
cannot be cast to types that do not represent COM components; however
they can be cast to interfaces as long as the underlying COM component
supports QueryInterface calls for the IID of the interface.
Does anyone know why I am not allowed to perform this operation ?
Apparently you can't do that below.
Dim tmp() as object = rs
rs (ADODB.RecordsetClass) a COM component cannot become/cast to a tmp()
array (System.Object[] -- [] means array).
You're going to have to read the recordset manually to load each record
into
the array maybe making object out of each record in the rs and loading an
object that represents the data of each record into the array.

Hi, thank you for helping me.

Here is the thing: when I do this

Dim Array() As Object = {ObjetDataSet1.Tables(0)}

the operation takes less than a second. It would be really great if
there was a way to do the same thing with a recordset (Dim array() as
object = rs). Maybe with a special kind of array ?
If I want to load each record in my array, it is gonna take more than
a minute, as my rs has more than 160000 records.

Any suggestion wil be greatly appreciated !


Thank you very much Michel Posseth and Mr Arnold, it works great now !
 
S

Scotty

news:54471eaf-abf0-4046-9532-4b0b2432c7b7@m23g2000hsc.googlegroups.com...
Hi everyone,
I am using Visual Basic 2005. My project is in vb.net.
After executing a request on an Access Table, I would like to copy my
recordset into an array as such:
Dim ConnectionString As String = "Provider=Microsoft.Jet.OLEDB.
4.0; Data Source=c:\myDataBase.mdb"
Dim sql As String = "SELECT * FROM [myTable];"
Dim conn1 As ADODB.Connection = New ADODB.Connection
conn1.Open(ConnectionString)
Dim rs As New ADODB.Recordset
rs = conn1.Execute(sql)
Dim tmp() as object = rs
The error message I get is:
Unable to cast COM object of type 'ADODB.RecordsetClass' to class type
'System.Object[]'. Instances of types that represent COM components
cannot be cast to types that do not represent COM components; however
they can be cast to interfaces as long as the underlying COM component
supports QueryInterface calls for the IID of the interface.
Does anyone know why I am not allowed to perform this operation ?
Apparently you can't do that below.
Dim tmp() as object = rs
rs (ADODB.RecordsetClass) a COM component cannot become/cast to a tmp()
array (System.Object[] -- [] means array).
You're going to have to read the recordset manually to load each record
into
the array maybe making object out of each record in the rs and loading an
object that represents the data of each record into the array.

Hi, thank you for helping me.

Here is the thing: when I do this

Dim Array() As Object = {ObjetDataSet1.Tables(0)}

the operation takes less than a second. It would be really great if
there was a way to do the same thing with a recordset (Dim array() as
object = rs). Maybe with a special kind of array ?
If I want to load each record in my array, it is gonna take more than
a minute, as my rs has more than 160000 records.

Any suggestion wil be greatly appreciated !


Thank you very much Michel Posseth and Mr Arnold, it works great now !
 
S

Scotty

news:54471eaf-abf0-4046-9532-4b0b2432c7b7@m23g2000hsc.googlegroups.com...
Hi everyone,
I am using Visual Basic 2005. My project is in vb.net.
After executing a request on an Access Table, I would like to copy my
recordset into an array as such:
Dim ConnectionString As String = "Provider=Microsoft.Jet.OLEDB.
4.0; Data Source=c:\myDataBase.mdb"
Dim sql As String = "SELECT * FROM [myTable];"
Dim conn1 As ADODB.Connection = New ADODB.Connection
conn1.Open(ConnectionString)
Dim rs As New ADODB.Recordset
rs = conn1.Execute(sql)
Dim tmp() as object = rs
The error message I get is:
Unable to cast COM object of type 'ADODB.RecordsetClass' to class type
'System.Object[]'. Instances of types that represent COM components
cannot be cast to types that do not represent COM components; however
they can be cast to interfaces as long as the underlying COM component
supports QueryInterface calls for the IID of the interface.
Does anyone know why I am not allowed to perform this operation ?
Apparently you can't do that below.
Dim tmp() as object = rs
rs (ADODB.RecordsetClass) a COM component cannot become/cast to a tmp()
array (System.Object[] -- [] means array).
You're going to have to read the recordset manually to load each record
into
the array maybe making object out of each record in the rs and loading an
object that represents the data of each record into the array.

Hi, thank you for helping me.

Here is the thing: when I do this

Dim Array() As Object = {ObjetDataSet1.Tables(0)}

the operation takes less than a second. It would be really great if
there was a way to do the same thing with a recordset (Dim array() as
object = rs). Maybe with a special kind of array ?
If I want to load each record in my array, it is gonna take more than
a minute, as my rs has more than 160000 records.

Any suggestion wil be greatly appreciated !


Thank you very much Michel Posseth and Mr Arnold, it works great now !
 
S

Scotty

Um, how about using ADO.Net instead? You obviously like the results that gives
you. Why do have to use ADODB?

If I use ADO.Net while working a an huge table with more than 150000
rows, it takes more than a minute to get the results into a
datagridview; that was too long for me :blush:
 
S

Scotty

Um, how about using ADO.Net instead? You obviously like the results that gives
you. Why do have to use ADODB?

If I use ADO.Net while working a an huge table with more than 150000
rows, it takes more than a minute to get the results into a
datagridview; that was too long for me :blush:
 
S

Scotty

Um, how about using ADO.Net instead? You obviously like the results that gives
you. Why do have to use ADODB?

If I use ADO.Net while working a an huge table with more than 150000
rows, it takes more than a minute to get the results into a
datagridview; that was too long for me :blush:
 
S

Steve Gerrard

Scotty said:
If I use ADO.Net while working a an huge table with more than 150000
rows, it takes more than a minute to get the results into a
datagridview; that was too long for me :blush:

You keep coming up against that 1 minute mark, huh. :)

Are you saying that you can load 'n' show 150000 records faster using ADODB than
ADO.Net?
 
M

Michel Posseth [MCP]

Not so verry much long ago we had a hughe discussion here about ACCESS
databases and VB.net

Ouch this is difficult for me but okay ,, if it is only speed you are after
DAO would be even much faster with Access as it is specilally optimized to
deal with ACCESS and seeing the opinions of other developers in that ng
thread it seems to be accepted to do so ( not in my office ) .

My personal opinion however is that you should not use ACCESS at all with a
..Net project i would favor SQL CE or one of it`s bigger brothers if possible


Another remark

This is a typical design flaw ,, a user doesn`t need 150000 records on his
screen , i wonder what your excuse is to do so :)


HTH

Michel
 
S

Scotty

You keep coming up against that 1 minute mark, huh. :)

Are you saying that you can load 'n' show 150000 records faster using ADODB than
ADO.Net?

Yes, that is what I am saying :)
57 seconds for ado.net aginst 1 second for Adodb :blush:
 
S

Scotty

Not so verry much long ago we had a hughe discussion here about ACCESS
databases and VB.net

Ouch this is difficult for me but okay ,, if it is only speed you are after
DAO would be even much faster with Access as it is specilally optimized to
deal with ACCESS and seeing the opinions of other developers in that ng
thread it seems to be accepted to do so ( not in my office ) .

My personal opinion however is that you should not use ACCESS at all with a
.Net project i would favor SQL CE or one of it`s bigger brothers if possible

Another remark


This is a typical design flaw ,, a user doesn`t need 150000 records on his
screen , i wonder what your excuse is to do so :)

HTH

Michel

"Mr. Arnold" <MR. (e-mail address removed)> schreef in bericht

Hi,


I don't think I can persuade my boss to change the use of Access, as
its whole code is based on this. I am not saying it would not be worth
it to take the time to adapt it to another database system but ... no
can do :blush:

About the design flaw, well..you are not the first one telling me
this, but it just has to be done :s

Thank you all for your time and help, really appreciated !
 
S

Steve Gerrard

Scotty said:
I don't think I can persuade my boss to change the use of Access, as
its whole code is based on this. I am not saying it would not be worth
it to take the time to adapt it to another database system but ... no
can do :blush:

You can open Access files with ADO.Net...
 
S

Steve Gerrard

Scotty said:
Yes, that is what I am saying :)
57 seconds for ado.net aginst 1 second for Adodb :blush:

I think you must be comparing apples and oranges.

While ado.net may not be a speed demon, it is not in general 57 times slower
than ADODB through COM. Perhaps you used too many gee-wizards to setup your
ADO.Net test, instead of just coding it directly like you did for ADODB.
 

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