Dataset problems

  • Thread starter Thread starter Lina
  • Start date Start date
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
 
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).
 
Hi Miha,

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

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
 
Hi Lina,

I guess Jon had a vision and already responded to your question before
you've even posted.
 
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
:o)


Is this normally the case?
 
Hi Miha and Jon,

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

:o)
 
Back
Top