本文介绍了创建数据集时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个包含6个表和5个关系的数据集。我在Form_Load事件中创建它。但是我一直收到以下错误...


system.data.dll中发生了'System.ArgumentNullException'类型的未处理异常

其他信息:''column''参数不能为null。

代码在此行停止...

Dim rel_Booking_CaraBook As New DataRelation(" dsFullBooking" ;,dsFullBooking.Tables(" dtBooking")。列(" Booking ID"),dsFullBooking.Tables(" dtCaraBooking")。列(" Boo kingID"))


有谁知道我做错了什么?

这是我的完整代码....


Dim dsFullBooking As New DataSet()

''创建客户数据表

da = New SqlDataAdapter(" SELECT * FROM Client",Cn)

da.Fill(dsFullBooking," dtClient")

''创建预订数据表

da =新SqlDataAdapter(" SELECT * FROM Booking",Cn)

da。填写(dsFul lBooking,dtBooking)

''创建Caravan_Booking数据表

da = New SqlDataAdapter(" SELECT * FROM Caravan_Booking",Cn)

da.Fill(dsFullBooking," dtCaraBooking")

''创建Room_booking数据表

da =新SqlDataAdapter(" SELECT * FROM Room_Booking",Cn)

da.Fill(dsFullBooking," dtRoomBooking")

''创建Meal_Booking数据表

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")。列(" ClientI D"))dsFullBooking.Relations.Add(rel_Client_Booking)


Dim rel_Booking_CaraBook As N ew 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")。列(" BookingID"),dsFullBooking.Tables(" dtRoomBooking")。列

(" BookingID"))


dsFullBooking.Relations.Add(rel_Booking_RoomBook)


''声明datarelation的列(复合键)

Dim RoomBookColumns(4)As DataColumn

Dim MealBookColumns(4)As DataColumn


RoomBookColumns(0)= dsFullBooking.Tables(" dtRoomBooking")。列(Boo kingID)

RoomBookColumns(1)= dsFullBooking.Tables(" dtRoomBooking")。Colu mns(Roo mID)

RoomBookColumns(2)= dsFullBooking.Tables(" dtRoomBooking")。列(" Roo mDt")

RoomBookColumns(3 )= dsFullBooking.Tables(" dtRoomBooking")。列(" Req _Session")

MealBookColumns(0)= dsFullBooking.Tables(" dtMealBooking")。列(" ; Boo kingID")

MealBookColumns(1)= dsFullBooking.Tables(" dtMealBooking")。Columns(" Roo mID")

MealBookColumns(2)= dsFullBooking .Tables(" dtMealBooking")。列(" Roo mDt")

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 )

感谢任何帮助

解决方案

你好翡翠,


你和我一起检查了所有的名字,比如BookingID这主要是一个案例

我做错了。


VB在这种情况下也是大小写的感觉


Cor




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("Booking ID"), dsFullBooking.Tables("dtCaraBooking").Columns("Boo kingID"))

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("ClientI D")) 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("Boo kingID")
RoomBookColumns(1) = dsFullBooking.Tables("dtRoomBooking").Columns("Roo mID")
RoomBookColumns(2) = dsFullBooking.Tables("dtRoomBooking").Columns("Roo mDt")
RoomBookColumns(3) = dsFullBooking.Tables("dtRoomBooking").Columns("Req _Session")

MealBookColumns(0) = dsFullBooking.Tables("dtMealBooking").Columns("Boo kingID")
MealBookColumns(1) = dsFullBooking.Tables("dtMealBooking").Columns("Roo mID")
MealBookColumns(2) = dsFullBooking.Tables("dtMealBooking").Columns("Roo mDt")
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

解决方案




这篇关于创建数据集时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 17:47