Dataset problems

L

Lina

Hi,

I am trying to create my own dataset and assign it to a
datagrid. However i keep encountering the following
error...

An unhandled exception of
type 'System.NullReferenceException' occurred in
microsoft.visualbasic.dll

Additional information: Object variable or With block
variable not set.

here is my code i am using in the form_load event....

Dim DTable1
DTable1.Columns.Add("Room Date",
Type.GetType("system.datetime"))
DTable1.Columns.Add("Room Name",
Type.GetType("system.varchar"))
DTable1.Columns.Add("Layout",
Type.GetType("system.varchar"))
DTable1.Columns.Add("Session",
Type.GetType("system.varchar"))
DTable1.Columns.Add("Guests",
Type.GetType("system.int32"))
DTable1.Columns.Add("Meal Type",
Type.GetType("system.varchar"))
DTable1.Columns.Add("Quantity",
Type.GetType("system.Int32"))

DataGrid1.DataSource = DTable1


Does anyone know what i am doing wrong??
The application seems to stop in the following line...
DTable1.Columns.Add("Room Date", Type.GetType
("system.datetime"))


thx in advance
 
M

Miha Markic

Hi Lina,

You are not creating a DataTable instance:
Dim DTable1 As New DTable1()
 
J

Jon Skeet [C# MVP]

Lina said:
Does anyone know what i am doing wrong??
The application seems to stop in the following line...
DTable1.Columns.Add("Room Date", Type.GetType
("system.datetime"))

Type.GetType(string) is case-sensitive. Use "System.DateTime" or
(preferrably) use TypeOf(DateTime).
 
L

Lina

Hi Miha,

I have made the ammended that u suggested. thx for that. I
dont know how i missed it :blush:)

I am getting another error that i have encountered before
but i did not know how to resolve it. The code stops on
the same line again...

DTable1.Columns.Add("Room Date", Type.GetType
("system.datetime"))

but this time i am getting the following error:

An unhandled exception of
type 'System.ArgumentNullException' occured in
system.data.dll

Additional information: 'dataType' argument cannot be
null.

Do u know what this is? I have not created any primary
keys on this datatable so i do not know why the coloumn
cannot be null when it is first created and loaded into my
datagrid!!

thx
 
M

Miha Markic

Hi Lina,

I guess Jon had a vision and already responded to your question before
you've even posted.
 
L

Lina

Thx Jon

The application no longer falls over on loading but the
datagrid still does not display any of the coloumn
headings i created for my empty dataTable!!!

i have used this line after craeting my dataTable...

DataGrid1.DataSource = DTable1

is this correct for making the coloumns i created to be
displayed or do i require more code?

Sorry for the many questions i ask. I am very new to VB.NET
:blush:)


Is this normally the case?
 
L

Lina

Hi Miha and Jon,

thx for taking the time to help me. I have just managed to
get the problem resolved with your help.

:blush:)
 

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