注册 登录
编程论坛 VB.NET论坛

[已解决]怎样在dataset中建立两表的关系。。

wuhongyao3 发布于 2007-12-20 09:16, 1189 次点击
Private Sub TableRelation(ByVal RelationName As String, ByVal ParentTableName As String, ByVal ParentColu As String, ByVal childTableName As String, ByVal childColu As String)
        ds.Relations.Add(RelationName, ds.Tables(ParentTableName).Columns(ParentColu), ds.Tables(childTableName).Columns(childColu))

    End Sub

    Public Function test() As DataSet
        RunselectSQL("select * from customers", "Cumtomers")
        RunselectSQL("select * from Orders", "Orders")
        RunselectSQL("select * from OrderDetails", "OrderDetails")
        TableRelation("CustomersAndOrders", "Customers", "CustomerID", "Orders", "CustomerID")
        Return ds
    End Function

这是我的代码

RunselectSQL是从数据库中读取数据,存放在DATASET中。。。。

提示错误是   Object reference not set to an instance of an object.

[[italic] 本帖最后由 wuhongyao3 于 2007-12-20 10:26 编辑 [/italic]]
2 回复
#2
bygg2007-12-20 09:47
RunselectSQL 这里是怎么写的??
#3
wuhongyao32007-12-20 09:55
问题解决了
呵呵,原来是我一个表名写错字母了。郁闷
请求锁帖吧。。。。
1