Refreshing DataTable
- From: "Simon" <simon_w3@xxxxxxxxxxxx>
- Date: 27 Jun 2005 07:35:41 -0700
Hi All,
I have a DataGrid bound to a DataTable. Every once in a while I need
to refresh the data in the table so that the updated data is displayed
in the DataGrid. Here's how I am attempting this:
'clear datatable
datatbl.Rows.Clear()
If PLCCount() <> 0 Then
'add rows to datatable containing PLC info
For p = 0 To PLCCount() - 1
Dim rowinfo As DataRow
rowinfo = datatbl.NewRow()
rowinfo("ID") = plcID(p)
rowinfo("Road") = PLCRoadName(p)
rowinfo("Start Time") = MyDate(plcStartTime(p))
rowinfo("End Time") = MyDate(plcEndTime(p))
rowinfo("Location") = plcLocationDescription(p)
rowinfo("Cause") = plcCause(p)
'add info to datatable
Try
'out-of-bounds error here
datatbl.Rows.Add(rowinfo)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Next p
'bind to datatable to datagrid
grdClosures.DataSource = datatbl
End If
I clear the rows in the DataTable and re-populate. However, when I try
and add the new rows i get an out-of-bounds exception in the Add
function.
This has something to do with the fact that I clear the rows and then
create new ones but I don't know nor understand why this is a problem.
Can anyone help?
Many thanks
Simon
.
- Follow-Ups:
- Re: Refreshing DataTable
- From: Cor Ligthert
- Re: Refreshing DataTable
- Prev by Date: Re: Choosing a new laptop
- Next by Date: Re: Why does this code not generate an error?
- Previous by thread: acceptbutton
- Next by thread: Re: Refreshing DataTable
- Index(es):