Inserting Row into Datatable
Inserting Row into Datatable
Inserting Row into Datatable
Inserting Row into Datatable
Inserting Row into Datatable
Inserting Row into Datatable Inserting Row into Datatable Inserting Row into Datatable Inserting Row into Datatable Inserting Row into Datatable Inserting Row into Datatable Inserting Row into Datatable Inserting Row into Datatable
Inserting Row into Datatable Inserting Row into Datatable
Inserting Row into Datatable
Go Back  Xtreme Visual Basic Talk > > > Inserting Row into Datatable


Reply
 
Thread Tools Display Modes
  #1  
Old 09-17-2006, 03:35 AM
dbaranas's Avatar
dbaranas dbaranas is offline
Regular
 
Join Date: Jun 2005
Location: Vancouver Island
Posts: 79
Default Inserting Row into Datatable


I am trying to insert a new row into a Dataset but it shows up in the XML file not quite in the right place

<?xml version="1.0" standalone="yes"?>
<Project>
<Buildings>
<Building>
<RefNo>1</RefNo>
<Name>Building 1</Name>
</Building>
</Buildings>
<Building>
<RefNo>0</RefNo>
<Name>Building 0</Name>
</Building>

</Project>

I am using this code to do it...the new row is inserted at the root level and not as a child of where it belongs. I tried inserting it into the "Buildings" table but it doesn't take it there


Code:
Public Class DataTables
    Public Sub AddBuilding(ByVal ref As Integer)

        Dim BuildingTable As DataTable = oProjectDS.Tables("Building")

        Dim Row As DataRow = BuildingTable.NewRow()
        Row("RefNo") = ref
        Row("Name") = "Building " & ref

        BuildingTable.Rows.Add(Row)

    End Sub
Reply With Quote
  #2  
Old 09-17-2006, 05:57 AM
shaul_ahuvaInserting Row into Datatable shaul_ahuva is offline
Ultimate Contributor

Retired Leader
* Expert *
 
Join Date: Jul 2003
Location: Camp Hill, PA
Posts: 1,992
Default

It's not inserting the elements in the wrong place - that's just how the DataTable serializes itself
Reply With Quote
  #3  
Old 09-18-2006, 04:39 AM
dbaranas's Avatar
dbaranas dbaranas is offline
Regular
 
Join Date: Jun 2005
Location: Vancouver Island
Posts: 79
Default

Quote:
Originally Posted by shaul_ahuva
It's not inserting the elements in the wrong place - that's just how the DataTable serializes itself
Thanks Shaul

I have been trying to figure out a way to force this to happen. The XML file must be structured this way for things to work below. I am trying to get serialized classes to be nested (collections of classes are already binary serialized in separate files)

This XML file is like an index so that classes will have nested relationships when it loads.

I have tried setting the relationships to nested but it creates duplicates of the nested structure for each top level object.....close but still not right

Code:
    Private Sub cmdLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLoad.Click

        Dim sPath As String = "f:\frmwhr\"
        oProjectDS.ReadXml(sPath & "Database.xml")

        'Me.WriteBinary(sPath & "Database.bin", oProjectDS)
        'oProjectDS = Me.ReadBinary(sPath & "Database.bin")

        If Not oProjectDS Is Nothing Then
            With oProjectDS.Relations
                .Add("StoreyToBuilding", oProjectDS.Tables("Building").Columns("RefNo"), oProjectDS.Tables("Storey").Columns("BuildingRefNo"))
                .Add("WallToStorey", oProjectDS.Tables("Storey").Columns("RefNo"), oProjectDS.Tables("Wall").Columns("StoreyRefNo"))
            End With
            With oProject
                If .Load(oProjectDS) Then
                    Dim oBuilding As Building
                    For Each oBuilding In oProject.Buildings
                        MessageBox.Show("Building = " & oBuilding.Name)
                        Dim oStorey As Storey
                        For Each oStorey In oBuilding.Storeys
                            MessageBox.Show("Storey = " & oStorey.Name)
                            Dim oWall As WallPanel
                            For Each oWall In oStorey.Walls
                                MessageBox.Show("Wall = " & oWall.Name)
                            Next
                        Next
                    Next
                Else
                    MessageBox.Show("Error Loading XML File")
                End If
            End With
        End If

    End Sub
Reply With Quote
  #4  
Old 09-19-2006, 07:27 AM
shaul_ahuvaInserting Row into Datatable shaul_ahuva is offline
Ultimate Contributor

Retired Leader
* Expert *
 
Join Date: Jul 2003
Location: Camp Hill, PA
Posts: 1,992
Default

Are you still pursuing this method of loading the data? If so, what is the oProject.Load method doing?
Reply With Quote
  #5  
Old 09-19-2006, 07:24 PM
dbaranas's Avatar
dbaranas dbaranas is offline
Regular
 
Join Date: Jun 2005
Location: Vancouver Island
Posts: 79
Default

Quote:
Originally Posted by shaul_ahuva
Are you still pursuing this method of loading the data? If so, what is the oProject.Load method doing?
Hi Shaul

No I found a workaround by binary serializing/deserializing a nested project class.

In Here...

I couldn't get the XML way figured out, the XML file was just a way to load up classes and build the relations.

Regards,
Dave
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Inserting Row into Datatable
Inserting Row into Datatable
Inserting Row into Datatable Inserting Row into Datatable
Inserting Row into Datatable
Inserting Row into Datatable
Inserting Row into Datatable Inserting Row into Datatable Inserting Row into Datatable Inserting Row into Datatable Inserting Row into Datatable Inserting Row into Datatable Inserting Row into Datatable
Inserting Row into Datatable
Inserting Row into Datatable
 
Inserting Row into Datatable
Inserting Row into Datatable
 
-->