Hi,
I am creating 2 datatables and am joining them via a
relationship i have created. I want to create a parent
child relationship in a datagrid (If this is possible???).
However i keep encountering the following error...
An unhandled exception of
type 'System.NullReferenceException' occurred in
Caravan.exe
Additional information: Object reference not set to an
instance of an object.
here is my code.....
'create empty dataset here so that the meal and room
bookings can be written to this before being pushed to
the database
Dim dataset1 As New DataSet()
Dim DataTable1 As New DataTable()
DataTable1 .Columns.Add("BookingNo", Type.GetType
("System.Int32"))
DataTable1 .Columns.Add("RoomID", Type.GetType
("System.Char"))
DataTable1 .Columns.Add("Room Date", Type.GetType
("System.DateTime"))
DataTable1 .Columns.Add("Req. Session",
Type.GetType("System.Char"))
DataTable1 .Columns.Add("Req. Layout",
Type.GetType("System.Char"))
DataTable1 .Columns.Add("Guests", Type.GetType
("System.Int32"))
'create the meal booking data table
Dim DataTable2 As New DataTable()
DataTable2.Columns.Add("BookingNo", Type.GetType
("System.Int32"))
DataTable2.Columns.Add("RoomID", Type.GetType
("System.Char"))
DataTable2.Columns.Add("RoomDt", Type.GetType
("System.DateTime"))
DataTable2.Columns.Add("Req. Session",
Type.GetType("System.Char"))
DataTable2.Columns.Add("Meal Type",
Type.GetType("System.Char"))
DataTable2.Columns.Add("Quantity", Type.GetType
("System.Int32"))
'add both tables into the dataset
dataset1 .Tables.Add(DataTable1)
dataset1 .Tables.Add(DataTable2)
'create a relationship between the two data tables
Dim ParentArray(4) As DataColumn
ParentArray(0) = dataset1.Tables
("DataTable1").Columns("BookingNo")
ParentArray(1) = dataset1.Tables
("DataTable1").Columns("RoomID")
ParentArray(2) = dataset1.Tables
("DataTable1").Columns("RoomDt")
ParentArray(3) = dataset1.Tables
("DataTable1").Columns("Req. Session")
Dim ChildArray(4) As DataColumn
ChildArray(0) = dataset1.Tables
("DataTable2").Columns("BookingNo")
ChildArray(1) = dataset1.Tables
("DataTable2").Columns("RoomID")
ChildArray(2) = dataset1.Tables
("DataTable2").Columns("RoomDt")
ChildArray(3) = dataset1.Tables
("DataTable2").Columns("Req. Session")
Dim relRoomToMealBooking As New DataRelation
("relRoomToMealBooking", ParentArray, ChildArray)
dataset1.Relations.Add(relRoomToMealBooking)
DataGrid1.DataSource = dataset1
Can anyone see what i am doin wrong??
The application seems to stop at this line...
ParentArray(0) = dsRoomMealBookingDisp.Tables
("DTableRoomBooking").Columns("BookingNo")
thx