Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - Re: Unable to cast COM object of type 'ADODB.RecordsetClass' to class type 'System.Object[]'

Reply
 
Old 03-24-2008   #1 (permalink)
Michel Posseth [MCP]


 
 

Re: Unable to cast COM object of type 'ADODB.RecordsetClass' to class type 'System.Object[]'


"Scotty" <matthieu.sarthou@xxxxxx> schreef in bericht
news:1b139922-a0c7-496c-b58d-cbe03f53ec7c@xxxxxx
Quote:

> 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 ?
Hello Scotty

just change
Dim tmp() as object = rs

to

Dim tmp() as object = rs.Getrows

and you have what you want

this link is valid as reference how to retrieve the records and fields
although it states Access developer it is exactly the same for classic ADO

http://msdn2.microsoft.com/en-us/library/bb221041.aspx


HTH

Michel Posseth [MCP]







My System SpecsSystem Spec
Old 03-26-2008   #2 (permalink)
Niko Suni


 
 

Re: Unable to cast COM object of type 'ADODB.RecordsetClass' to class type 'System.Object[]'

Hey Michel,

"Dim tmp() as object" declares an array of objects. Since the recordset is a
single object, it cannot be cast to an array by itself.

To correct this, rewrite the statement without the brackets "()".

HTH,
-Niko
MVP, Windows/DirectX


"Michel Posseth [MCP]" <MSDN@xxxxxx> wrote in message
news:eFaHxZZjIHA.5080@xxxxxx
Quote:

>
> "Scotty" <matthieu.sarthou@xxxxxx> schreef in bericht
> news:1b139922-a0c7-496c-b58d-cbe03f53ec7c@xxxxxx
Quote:

>> 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 ?
>
> Hello Scotty
>
> just change
> Dim tmp() as object = rs
>
> to
>
> Dim tmp() as object = rs.Getrows
>
> and you have what you want
>
> this link is valid as reference how to retrieve the records and fields
> although it states Access developer it is exactly the same for classic ADO
>
> http://msdn2.microsoft.com/en-us/library/bb221041.aspx
>
>
> HTH
>
> Michel Posseth [MCP]
>
>
>
>
>
>
My System SpecsSystem Spec
Old 03-27-2008   #3 (permalink)
Michel Posseth [MCP]


 
 

Re: Unable to cast COM object of type 'ADODB.RecordsetClass' to cl

Hello Niko ,
Quote:

> "Dim tmp() as object" declares an array of objects. Since the recordset is a
> single object, it cannot be cast to an array by itself.
>
no not the recordset itself but the rs.Getrows method as i showed can

Dim tmp() as object = rs.Getrows

the rs.Getrows method returns the recordset as a variant array in VB.Net ,
C# you can use a object array instead

This wil return a multi dimensioned object array containing all row and
column data

The link i provided ( VBA ) shows how to loop through the records and
fields

HTH

Michel




"Niko Suni" wrote:
Quote:

> Hey Michel,
>
> "Dim tmp() as object" declares an array of objects. Since the recordset is a
> single object, it cannot be cast to an array by itself.
>
> To correct this, rewrite the statement without the brackets "()".
>
> HTH,
> -Niko
> MVP, Windows/DirectX
>
>
> "Michel Posseth [MCP]" <MSDN@xxxxxx> wrote in message
> news:eFaHxZZjIHA.5080@xxxxxx
Quote:

> >
> > "Scotty" <matthieu.sarthou@xxxxxx> schreef in bericht
> > news:1b139922-a0c7-496c-b58d-cbe03f53ec7c@xxxxxx
Quote:

> >> 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 ?
> >
> > Hello Scotty
> >
> > just change
> > Dim tmp() as object = rs
> >
> > to
> >
> > Dim tmp() as object = rs.Getrows
> >
> > and you have what you want
> >
> > this link is valid as reference how to retrieve the records and fields
> > although it states Access developer it is exactly the same for classic ADO
> >
> > http://msdn2.microsoft.com/en-us/library/bb221041.aspx
> >
> >
> > HTH
> >
> > Michel Posseth [MCP]
> >
> >
> >
> >
> >
> >
>
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
testing parameter for com object type PowerShell
discovering the type of an object PowerShell
Passing credential object - what's the type? PowerShell
Parse Log files into a strongly type Object PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46