Please Help with Datatable within Dataset

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
 
K

Ken Tucker [MVP]

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
 
M

Merlin

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
 
C

Cor

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
 
M

Merlin

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top