![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 ? 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 Specs![]() |
| | #2 (permalink) |
| | 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 Specs![]() |
| | #3 (permalink) |
| | 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. > 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 Specs![]() |
![]() |
| 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 | |||