Error creating a dataset

G

Guest

Hi, I am trying to create a dataset with 6 tables and 5 relationships created between them. I am creating it in the Form_Load event. However i keep getting the following error...

An unhandled exception of type 'System.ArgumentNullException' occurred in system.data.dll
Additional information: 'column' argument cannot be null.

The code stops on this line...
Dim rel_Booking_CaraBook As New DataRelation("dsFullBooking", dsFullBooking.Tables("dtBooking").Columns("BookingID"), dsFullBooking.Tables("dtCaraBooking").Columns("BookingID"))

Does anyone know what im doin wrong??
Here is my full code....

Dim dsFullBooking As New DataSet()
'create the customer datatable
da = New SqlDataAdapter("SELECT * FROM Client", Cn)
da.Fill(dsFullBooking, "dtClient")
'create the booking datatable
da = New SqlDataAdapter("SELECT * FROM Booking", Cn)
da.Fill(dsFullBooking, "dtBooking")
'create the Caravan_Booking datatable
da = New SqlDataAdapter("SELECT * FROM Caravan_Booking", Cn)
da.Fill(dsFullBooking, "dtCaraBooking")
'create the Room_booking datatable
da = New SqlDataAdapter("SELECT * FROM Room_Booking", Cn)
da.Fill(dsFullBooking, "dtRoomBooking")
'create the Meal_Booking datatable
da = New SqlDataAdapter("SELECT * FROM Meal_Bookings", Cn)
da.Fill(dsFullBooking, "dtMealBooking")



'----------Relationships
Dim rel_Client_Booking As New DataRelation("dsFullBooking", dsFullBooking.Tables
("dtClient").Columns("ClientID"), dsFullBooking.Tables("dtBooking").Columns("ClientID")) dsFullBooking.Relations.Add(rel_Client_Booking)

Dim rel_Booking_CaraBook As New DataRelation("dsFullBooking", dsFullBooking.Tables
("dtBooking").Columns("BookingID"), dsFullBooking.Tables("dtCaraBooking").Columns
("BookingID"))
dsFullBooking.Relations.Add(rel_Booking_CaraBook)


Dim rel_Booking_RoomBook As New DataRelation("dsFullBooking", dsFullBooking.Tables
("dtBooking").Columns("BookingID"), dsFullBooking.Tables("dtRoomBooking").Columns
("BookingID"))

dsFullBooking.Relations.Add(rel_Booking_RoomBook)

'Declare the Columns for the datarelation (for compound keys)
Dim RoomBookColumns(4) As DataColumn
Dim MealBookColumns(4) As DataColumn

RoomBookColumns(0) = dsFullBooking.Tables("dtRoomBooking").Columns("BookingID")
RoomBookColumns(1) = dsFullBooking.Tables("dtRoomBooking").Columns("RoomID")
RoomBookColumns(2) = dsFullBooking.Tables("dtRoomBooking").Columns("RoomDt")
RoomBookColumns(3) = dsFullBooking.Tables("dtRoomBooking").Columns("Req_Session")

MealBookColumns(0) = dsFullBooking.Tables("dtMealBooking").Columns("BookingID")
MealBookColumns(1) = dsFullBooking.Tables("dtMealBooking").Columns("RoomID")
MealBookColumns(2) = dsFullBooking.Tables("dtMealBooking").Columns("RoomDt")
MealBookColumns(3) = dsFullBooking.Tables("dtMealBooking").Columns("Req_Session")

Dim rel_RoomBook_MealBook As New DataRelation("myRelationName", RoomBookColumns,
MealBookColumns, True)
dsFullBooking.Relations.Add(rel_RoomBook_MealBook)


any help is appreciated
 
C

Cor

Hi Jade,

Did you check all the names like BookingID with me this is mostly a case
error that I did make.

VB is in this case also case sensetive

Cor
 
G

Guest

Hi Cor

I have checked all the coloumn names and they all match up to what is in my database!
What i wasnt sure about is if i need to use the SQLDataReader to place a single value into a textbox. Is this the easiest/best way to do this?

This is the code i found on the net to add values to a combobox. I modified it for my purposes

Is it correct?
 
G

Guest

Hi Cor,

I have checked all the column headings and they are correct!!!
Is my syntax correct? I used a web example to get this code which i tailored to my own needs.



btw, do not read my post below this as i posted here by accident. :blush:)
 
C

Cor

Hi Jade,

For me it becomes also guessing now, but I see you did give all your
datarelations the name
"dsFullBooking" maybe if you give them an unique name (that is as I use it)

Cor

">
I have checked all the column headings and they are correct!!!
Is my syntax correct? I used a web example to get this code which i
tailored to my own needs.
 
G

Guest

Hi Cor

I have elimated many of the errors i have and i am on the last part of my code now. :blush:

I am getting the following error..
An unhandled exception of type 'System.ArgumentNullException' occurred in system.data.dl
Additional information: 'column' argument cannot be null

the code stops at this line...
Dim rel_RoomBook_MealBook As New DataRelation("rel_RoomBook_MealBook",
RoomBookColumns, MealBookColumns, True

the code for this relationship is listed below. This relationship is coded differently to the other as both relations contain a compound key.
do u know what this message concerns?? could it be anything to do with the fact that the meal_Booking table in my database does not contain any data therefore it has nothing to join with on the room_bookings table??? Can the data affect this

'Declare the Columns for the datarelation (for compound keys
Dim RoomBookColumns(4) As DataColum
Dim MealBookColumns(4) As DataColum

RoomBookColumns(0) = dsFullBooking.Tables("dtRoomBooking").Columns("BookingNo"
RoomBookColumns(1) = dsFullBooking.Tables("dtRoomBooking").Columns("RoomID"
RoomBookColumns(2) = dsFullBooking.Tables("dtRoomBooking").Columns("RoomDt"
RoomBookColumns(3) = dsFullBooking.Tables("dtRoomBooking").Columns("Req_Session"

MealBookColumns(0) = dsFullBooking.Tables("dtMealBooking").Columns("BookingNo"
MealBookColumns(1) = dsFullBooking.Tables("dtMealBooking").Columns("RoomID"
MealBookColumns(2) = dsFullBooking.Tables("dtMealBooking").Columns("RoomDt"
MealBookColumns(3) = dsFullBooking.Tables("dtMealBooking").Columns("Req_Session"

'Add the name and DataColumn arrays to the Relatio
Dim rel_RoomBook_MealBook As New DataRelation("rel_RoomBook_MealBook",
RoomBookColumns, MealBookColumns, True
'Add the Relation to the DataSe
dsFullBooking.Relations.Add(rel_RoomBook_MealBook)
 
C

Cor

Hi Jade,
the code for this relationship is listed below. This relationship is coded
differently to the other as both relations contain a compound key.
do u know what this message concerns?? could it be anything to do with the
fact that the meal_Booking table in my database does not contain any data
therefore it has nothing to join with on the room_bookings table??? Can the
data affect this?

I thik you are right

I would try what the fillschema could do for me

http://msdn.microsoft.com/library/d...tacommondbdataadapterclassfillschematopic.asp

you have than an empty dataset with a good schema

Cor
 

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