PC Review


Reply
Thread Tools Rate Thread

Can't display dataset in windows form datagrid

 
 
=?Utf-8?B?dml0YQ==?=
Guest
Posts: n/a
 
      28th Mar 2005
Hi all, i have a window application which make use of a timer class, whereby
every 5 seconds i have to refresh a datagrid,below is the codes

Public Sub TimerFired(ByVal sender As Object, _
ByVal e As System.Timers.ElapsedEventArgs)




'Label1.Text = "Server Time = " & e.SignalTime.ToString
tape()
end sub
Private Function tape()

Dim i As Integer
Dim ds3 As New DataSet
Dim ds4 As New DataSet
ds4 = a.RetrievePatient1()
Dim foodtable As DataTable
Dim idcolumn As DataColumn
Dim namecolumn As DataColumn
Dim foodemandcolumn As DataColumn

Dim row As DataRow
'make a table
foodtable = New DataTable("Food")

'make a column
idcolumn = New DataColumn("PatientID")
idcolumn.DefaultValue = "<PatientID>"
'idcolumn.DataType = Type.GetType("System.string")
foodtable.Columns.Add(idcolumn)

namecolumn = New DataColumn("Name")
idcolumn.DefaultValue = "<Name>"
'idcolumn.DataType = Type.GetType("System.string")
foodtable.Columns.Add(namecolumn)

foodemandcolumn = New DataColumn("DemandFood")
foodemandcolumn.DefaultValue = "<DemandFood>"
'idcolumn.DataType = Type.GetType("System.string")
foodtable.Columns.Add(foodemandcolumn)

'a.RetrievePatient(patID)
'add row of data
For i = 0 To ds4.Tables(0).Rows.Count() - 1
'If TextBox1.Text = ds3.Tables(0).Rows(i)(0) Then
row = foodtable.NewRow
row("PatientID") = ds4.Tables(0).Rows(i)("PatientID")
row("Name") = ds4.Tables(0).Rows(i)("Name")
row("DemandFood") = ds4.Tables(0).Rows(i)("DemandFood")
foodtable.Rows.Add(row)





'DataGrid2.SetDataBindinga(ds2,"DemanfFood)

'End If
Next
ds4.Tables.Add(foodtable)

DataGrid2.SetDataBinding(ds4, "Food")
End Function
With the above coding data could not be retrieve to the datagrid
*datagrid couls br filled if the above codes are placed in a Form_Load or
button_Onclick

vitz...
 
Reply With Quote
 
 
 
 
=?Utf-8?B?d2pvdXN0cw==?=
Guest
Posts: n/a
 
      28th Mar 2005
It looks like every time your timer fires and calls tape() you are adding
another table with the name "food" to your dataset. That should throw a
DuplicateNameException. Remove your old table (or repopulate it instead of
creating a new one) before you try and retrieve new data.

"vita" wrote:

> Hi all, i have a window application which make use of a timer class, whereby
> every 5 seconds i have to refresh a datagrid,below is the codes
>
> Public Sub TimerFired(ByVal sender As Object, _
> ByVal e As System.Timers.ElapsedEventArgs)
>
>
>
>
> 'Label1.Text = "Server Time = " & e.SignalTime.ToString
> tape()
> end sub
> Private Function tape()
>
> Dim i As Integer
> Dim ds3 As New DataSet
> Dim ds4 As New DataSet
> ds4 = a.RetrievePatient1()
> Dim foodtable As DataTable
> Dim idcolumn As DataColumn
> Dim namecolumn As DataColumn
> Dim foodemandcolumn As DataColumn
>
> Dim row As DataRow
> 'make a table
> foodtable = New DataTable("Food")
>
> 'make a column
> idcolumn = New DataColumn("PatientID")
> idcolumn.DefaultValue = "<PatientID>"
> 'idcolumn.DataType = Type.GetType("System.string")
> foodtable.Columns.Add(idcolumn)
>
> namecolumn = New DataColumn("Name")
> idcolumn.DefaultValue = "<Name>"
> 'idcolumn.DataType = Type.GetType("System.string")
> foodtable.Columns.Add(namecolumn)
>
> foodemandcolumn = New DataColumn("DemandFood")
> foodemandcolumn.DefaultValue = "<DemandFood>"
> 'idcolumn.DataType = Type.GetType("System.string")
> foodtable.Columns.Add(foodemandcolumn)
>
> 'a.RetrievePatient(patID)
> 'add row of data
> For i = 0 To ds4.Tables(0).Rows.Count() - 1
> 'If TextBox1.Text = ds3.Tables(0).Rows(i)(0) Then
> row = foodtable.NewRow
> row("PatientID") = ds4.Tables(0).Rows(i)("PatientID")
> row("Name") = ds4.Tables(0).Rows(i)("Name")
> row("DemandFood") = ds4.Tables(0).Rows(i)("DemandFood")
> foodtable.Rows.Add(row)
>
>
>
>
>
> 'DataGrid2.SetDataBindinga(ds2,"DemanfFood)
>
> 'End If
> Next
> ds4.Tables.Add(foodtable)
>
> DataGrid2.SetDataBinding(ds4, "Food")
> End Function
> With the above coding data could not be retrieve to the datagrid
> *datagrid couls br filled if the above codes are placed in a Form_Load or
> button_Onclick
>
> vitz...

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to display data on a Windows form (without using a datagrid)?.. Peter Demeyer Microsoft Dot NET Framework Forms 3 24th Sep 2006 09:30 PM
C# Windows Form DataGrid and DataSet example Jason Huang Microsoft C# .NET 0 7th Dec 2005 10:29 AM
c# windows form DataGrid and DataSet Jason Huang Microsoft C# .NET 0 7th Dec 2005 08:43 AM
How to Display images in a Windows Form DataGrid =?Utf-8?B?VmFs?= Microsoft C# .NET 1 12th Sep 2005 02:39 PM
Problem with display custom datagrid in Windows form phamtasmic Microsoft C# .NET 0 27th Jan 2005 03:44 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:21 PM.