can't add a datatable to a dataset

Pedro

Member
Joined
Nov 7, 2009
Messages
5
Programming Experience
Beginner
Hello, can anyone help me figure out this? I've created a dataset and two datatables, i've added both to the dataset, with no errors from the debugger. But when i try to establish a datarelation between the two datatables, i got an error "datatable is not a member of system.data.dataset".
I don't figure out what i've made wrong...
If it helps, here goes a litle code

VB.NET:
Public Class CalcEixo


    Dim ObraDataSet As New DataSet()

    Dim Tipo As String = ""
    Dim Pkini As Double
    Dim Pkfin As Double
    Dim pk_n As Double
    Dim pk_f As Double
    Dim Pkcurr As Double
    Dim ligacao As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source= c:\obra.mdb;"
    Dim CN As New OleDb.OleDbConnection(ligacao)
    Dim drCurr As DataRow







    Public Sub Calcular_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Calcular.Click



        Dim dtCotasEixo As New DataTable()
        ObraDataSet.Tables.Add(dtCotasEixo)
        Dim dtList As New DataTable("dtList")
        With dtList
            .Columns.Add("Pk")
            .Columns.Add("M")
            .Columns.Add("P")
            .Columns.Add("Z")
            .Columns.Add("Rumo")
        End With

        ObraDataSet.Tables.Add(dtList)

later,

VB.NET:
Dim dtList1 As DataTable = ObraDataSet.dtList
        Dim dtCotasEixo1 As DataTable = ObraDataSet.dtCotasEixo

        Dim dtListPk As DataColumn = dtList.Columns("Pk")
        Dim dtCotasEixoPk As DataColumn = dtCotasEixo.Columns("Pk")
        Dim DR As DataRelation
        DR = New DataRelation("xyz", dtListPk, dtCotasEixoPk)


        Dim novalinha As DataRow

        For Each novalinha In dtList(0).GetChildRows("xyz")
            MsgBox(novalinha.Item(1).ToString)
        Next

some help would be apreciated, i'm just a beginner...very beginner:(
 
Typing this in directly so it may have small errors.

VB.NET:
Dim listPk As DataColumn = ObraDataSet.dtList.Columns("Pk")
Dim cotasPk As DataColumn = ObraDataSet.dtCotasEixo.Columns("Pk")
Dim relListCotas As New DataRelation("xyz", listPk, cotasPk)
ObraDataSet.Relations.Add(relListCotas)
 
datatable not a system.data.dataset

thanks for being so kind, but it's not working, keeps telling me "dtList not a system.data.dataset" and ""dtCotasEixo not a system.data.dataset". I don't even see a dataset on the solution explorer...inspite of i having coded it!
Do i have to declare it on a Module, or something alike? It must be something simple, and i'm feeling very stupit about this...:(
 
you wont see the dataset in solution explorer because you've coded it inside your main file! Solution explorer shows you files in your project.. THink about it; every time you Dim a string, or an Integer, it doesnt show in solution explorer ;)


I'd thoroughly recommend you scrap your current approach entirely and instead do:

Open solution explorer
Right click the project
Choose Add New Item
From the panel that appears, choose Dataset, and name it
A dataset file has appeared
Open it, and you see a designer surface (see the DDS link in my signature)

Use this to design your tables; the end result will be achieved faster, it will be better coded and it will work! :)
 
Back
Top