HELP - Functionality of a disconnected RECORDSET in .NET

tina33
04-03-2004, 01:41 AM
Hi Good People

I'm a newbie in .NET and looking for help in getting my small project started. I'm using textbox controls on a form to capture some details and create an in-memory cache of my records before I eventually save the collection of records created to an XML file.

The form will also have commandbuttons to allow me to insert a new record, go next record, got first record, etc (similar to the methods of a recordset). Each time I navigate to a different record, the textbox contents on the form should reflect the change. A SUBMIT command button should write all these records in memory to an XML file.

How can I allow navigation from one record to another, as well as record changes just the way we do in VB6.0 using the Recordset object? I couldn't see any way of doing it. Which object(s) in the Dataset namespace can I use?

PLEASE HELP!! Here's a simplified version of my code snippet:

Public Shared Sub SaveRecordsInDatatable
CreateDataSet
'Add data to table
Dim i As Integer
For i = 0 To 10
dr = dt.NewRow
dr("name") = txtName.text
dr("surname") = txtSurname.text
dr("DOB") = txtDOB.text
dt.Rows.Add(dr)
Next i

End Sub

Public Shared Sub CreateDataset()
Dim dt As New DataTable
Dim dc As DataColumn
Dim dr As DataRow

' Create new DataRow objects
'create name column
dc = New DataColumn
dc.DataType = System.Type.GetType("System.String")
dc.ColumnName = "name"
dt.Columns.Add(dc)

' Create surname column.
dc = New DataColumn
dc.DataType = Type.GetType("System.String")
dc.ColumnName = "surname"
dt.Columns.Add(dc)

' Create Date Of Birth column.
dc = New DataColumn
dc.DataType = Type.GetType("System.String")
dc.ColumnName = "DOB"
dt.Columns.Add(dc)
End Sub


P/S - some code snippets would help. Thanks.

MKoslof
04-03-2004, 08:28 AM
Ok, this is how I recommend doing this. Create a public class called "navigateRecords" in this class you load all your data into your dataTable. Then, within this class you also have the code for your move next, move previous, move first button clicks...I have included the relevant declarations and code for moving through the DataTable..




'within your top level class declarations

Public DR As DataRow
Public RowCount As Integer
Public i As Integer

'now in the Move_Next button

If i = RowCount - 1 Then Return

i = i + 1

DR = dataTable.Rows(i)
txt_box.Text = DR(i)


'In the move previous button

If i = -1 Or i = 0 Then
i = 0
Return
End If

i = i- 1
DR = dataTable.Rows(i)
txt_Box.Text = DR(0)

'in the moveFirst buttion

i = 0

DR = dataTable.Rows(i)
txt_OwnerID.Text = DR(0)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum