Please Help with Datatable within Dataset

  • Thread starter Thread starter Merlin
  • Start date Start date
M

Merlin

Why does the following only work once? If I put the grid code in a button
and click once the grid is populated, if I click the button a further times
the grid has no data! What I'm attempting to do below is put a Datatable
within a Dataset and show the results in the grid, then clear the Datatable
and Dataset and repopulate with new data.

Many thanks,

Merlin

Please note the code is simplified for example purpose; use of the Dataset
is so I can setup relational data .
'// The following code uses Microsofts standard DataGrid

'// Declarations Section
Dim dataset As New Dataset
Dim DT As New DataTable("DT")
Private row As DataRow = DT.NewRow()

'// Code to put data within grid
DT.Reset()
dataset.Reset()

Dim colWork As New DataColumn("Line", GetType(Integer))
colWork.ReadOnly = True
DT.Columns.Add(colWork)

Dim Keys(0) As DataColumn
Keys(0) = colWork
'DT.PrimaryKey = Keys

colWork = New DataColumn("Part", GetType(String))
DT.Columns.Add(colWork)

For i As Integer = 1 To 5
row = DT.NewRow()
row(0) = i.ToString
row(1) = ""
DT.Rows.Add(row)
Next

dataset.Tables.Add(DT)

DataGrid1.DataSource = dataset
 
Hi,

Set the datagrid datasource to the datatable instead of the dataset
other wise it just shows a + in the corner for you to expand to get to the
data. Datagrid1.DataSource = DT

Ken
 
Hi Ken,

I need to set the Datasource as Dataset as I'm storing multiple tables
within this and handling the relationships between them. In my project I'm
not actually using the MS Grid, but the Infragistics UltraGrid just thought
this was the simplest way to show my problem.

Regards,
Merlin
 
Hi Merlin,

It is not to see what that reset does, when you want a quick solution you
can try this.

If ds.Tables.Count > 0 Then
ds.Tables.Remove("DT")
End If
DT = New DataTable("DT")

I removed both those resets.

Cor
 
Thanks Cor,

I used the DT=New DataTable("DT") and Dataset = New Dataset and that has
solved my problem, the reset method would not appear to work properly.

Merlin.
 
Back
Top