473,414 Members | 1,843 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Trying to pass a Table to a VB.Net Class

Hello -

From an Access VBA module, I'm trying to pass a Table to a VB.Net class.

I'm getting the following error running the VBA:

"Unable to cast object of type System._ComObject to type
System.Data.Datatable"

The code resulting in the error looks like the following
In VBA:
Dim mclass As myClass
Set mclass = New myClass

Set mclass.ContractTable = CurrentDb().OpenRecordset("Contract")

In VB.Net:

Public Class myClass

Private myrstContract As Data.DataTable

WriteOnly Property ContractTable() As DataTable
Set(ByVal Value As DataTable)
myrstContract = Value
End Set
End Property

End Class

Suggestions?

Thank you as always,
Mark
Nov 21 '05 #1
2 2995
er, let me ask the obvious: why do it this way? you can get to the
table via the OleDbDataAdapter and related objects... it makes sense
to let ADO.NET do the work and not to spend hours trying to shoe-horn
the table into a DataTable object.

http://msdn.microsoft.com/library/de...classtopic.asp

Nov 21 '05 #2
VBA doesn`t know the DataTable data type and VB.Net doesn`t know what to do
with the recordset object type

so there is your problem
well you could solve this in diferent ways

1 . you could make a method in your VB.Net class that loads the data by
passing it`s tablename ( with ADO.Net through Oledb )

like this
Friend Function fDtDataExecute(ByVal SQL As String) As DataTable

Try

Dim da As New OleDbDataAdapter

da.SelectCommand = New OleDbCommand(SQL, _objCon)

fDtDataExecute = New DataTable

da.Fill(fDtDataExecute)

da.Dispose()

Catch ex As Exception

_exception = ex

End Try

End Function
2.
or you could set a reference to classic ADO in VB.Net and work with the
passed recordset
( the two types are now the same in VBA and VB.Net and can be passed from
one to the other )

please note that the first method will give you the highest performance

regards

Michel Posseth

"Mark" <Ma**@discussions.microsoft.com> wrote in message
news:F7**********************************@microsof t.com...
Hello -

From an Access VBA module, I'm trying to pass a Table to a VB.Net class.

I'm getting the following error running the VBA:

"Unable to cast object of type System._ComObject to type
System.Data.Datatable"

The code resulting in the error looks like the following
In VBA:
Dim mclass As myClass
Set mclass = New myClass

Set mclass.ContractTable = CurrentDb().OpenRecordset("Contract")

In VB.Net:

Public Class myClass

Private myrstContract As Data.DataTable

WriteOnly Property ContractTable() As DataTable
Set(ByVal Value As DataTable)
myrstContract = Value
End Set
End Property

End Class

Suggestions?

Thank you as always,
Mark

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Henry | last post by:
I hope someone can help me on this. I have two controls on a form. the first is a comboBox the second is a datagrid. Both controls are bound to tables in a common dataset. What I am trying to...
7
by: klynn | last post by:
I'm wondering what the best way to do the following: I have a page with a table. I built a custom class that creates a System.Web.UI.WebControls table object and return it to the webpage as a...
5
by: Charles Krug | last post by:
List: I have this: # classC.py class C(object): pass class D(C): pass
1
by: Bruce HS | last post by:
I'm using VS2005, VB, WinForms I’ve developed forms using those nice wizards Microsoft provides. However, I’m running into a couple of complications trying to work with the resulting Table...
5
by: timothy.pollard | last post by:
Hi I'm having a bit of bother trying to make a questionnaire do what I want it to. I have put it up on www.web-iq.co.uk/test.htm. Basically the user of the final form (when I've tarted it up)...
4
by: darrel | last post by:
I posted a question below and GroupReader suggested I look into constructors as the solution to my problem. So, that's what I'm doing, but I'm a little hung up on how to pass data back to my...
2
by: ELINTPimp | last post by:
Hello all, Have a really interesting problem (at least to me) with my upload_file() function. I have it working now, with a bit of a work around, but would like to know what everyone thinks in...
1
by: rsteph | last post by:
I've got some product information pages, with images and text, all setup within a table. I'm trying to add a small image in the upper right hand corner of the content div (where all the important...
1
by: John Wright | last post by:
I have a class that I populate properties from a table in my database. I create the properties in my class one for one with the columns in the tables that I use to fill the class. Some properties...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.