I can't use DataTable, type expected

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I can't use DataTable!
I try to write ( in form load):

Dim myDataTable As DataTable = New DataTable("ParentTable")

I then get "Type expected" for the DataTable (in Task List)
I have included "Imports System.Data"
(Tried Imports System.DataTable, and other Imports)
I have Visual Basic .net 2002 (ver 7.0 I think).
Is it to old, is there something else I have to do?

Is there an other way to show the user a table with content from a xml file!?

Best Regard

-bodil-
 
Hi,

How can one impote System.DataTable

This piece of code works

Imports System.Data is enough
Dim myDataTable As DataTable = New DataTable("ParentTable")

Remove "Imports System.DataTable" etc & see if that works
Alternatively, you can write

Dim myDataTable As DataTable
set myDataTable = New DataTable("ParentTable")

HTH
Kalpesh
 
I wrote wrong, I ment System.Data.Datatable, not system.datatable.
I have copied many example (found on the internet and in msdn)
But I still get the message: "type expected" for DataTable
I now think that is not the "imports" that are wrong, it it something else.
(the error message for missing imports: "Type 'StreamReader' is not defined.)

I read this in vb.net Help
--------------------------------
"Source code characters occur that are not recognizable as a type name. The
context calls for either an elementary data type or a declared element name
representing a type.

To correct this error

1. Check that the type has been defined.
2. Check that the type name is spelled correctly. "

----------------------------------------

How can I check 1 and 2?

best regards

-bodil-
 
Bodil,

As you wrote it, it should work.

(In VBNet 2002/2003 in 2005 you have to add the reference to system.data)

The import is default done for this in your project properties in VBNet.

Can you try a new windowsform project and than paste this code in the load
event.
Dim myDataTable As DataTable = New DataTable("ParentTable")

Withouth doing anything more

Cor
 
Thank You! That works!
I don't know what I did before, but now it works?!
I thought I had a normal win app project, but maybe it got corrupt when I
copied som code from another project!?

Thank you for you help!

Best Regards

Bodil
 
Back
Top