Datagrid Reset

jdink22

Member
Joined
Jun 16, 2003
Messages
10
i have a datagrid that i am populating with two tables, one of which comes from a sql table, the other is programmatically generated. the first table is just populated with dates, according to the value the user selects in a date/time picker. so the date table is populated and then related to a task table via the date field. the problem i am having is that when the user selects a date, the grid populates with related data from both tables (as it should). However, when the user attempts to select another date in the same session, the dataset will not repopulate. i was getting an error about the table already being in the dataset (which makes sense, because it was generated the first time the user picked a date). so....i tried to delete the dataset, but it said i needed to delete the relationship, and then it says i need to delete the foreign key constraints....and so on. so i opted to "reset" the dataset if it already existed so that it would repopulate upon selecting another date. now what i am getting is a blank table, but it does not crash. any ideas on how to approach this?
 
did you try with this:

Code:
Dim myDataset as New DataSet()
Dim myTable as New DataTable()

to add myTable to myDataset
myDataset.Tables.Add(myTable)
to remove myTable form dataset
myDataset.Tables.Remove(myTable)

:D
 
sizer-thanks for the quick response. yes, i did try removing the table but when i do, i get this error:**An unhandled exception of type System.ArgumentException occurred in system.data.dll - Additional information: Cannot remove a table that has existing relations. Remove relations first.** So then i tried to both clear and remove the relationship and got this error: **An unhandled exception of type System.ArgumentException occurred in system.data.dll - Additional information: Cannot remove table Temp_Dates, because it referenced in ForeignKeyConstraint DatesToJobItems. Remove the constraint first.** and this is where i am stuck and why i tried to go with the "reset" route. any ideas?
 
try to remove constrains with
Code:
myTable.Constrains.Clear()
that should help if not post some code please!
:D
 
i got the same error upon trying to remove the constraints. i am including my code if you have time to look at it. i feel like im probably just going about the order of things incorrectly, as i am a first time coder....but if you do have time, id greatly appreciate some help!!! :confused:
 

Attachments

Whenever a DataRelation is added to a DataSet, a ForeignKeyConstraint and UniqueConstraint are added automatically to the parent table and the child table. The UniqueConstraint is applied to the primary key column of the parent table, and the ForeignKeyConstraint is applied to the foreign key column of the child table. In that case, attempting to remove the UniqueConstraint will cause an exception to be thrown because the ForeignKeyConstraint must be removed first. To avoid this, use the CanRemove method to determine if a UniqueConstraint can be removed.

for more info see
http://msdn.microsoft.com/library/d...taconstraintcollectionclasscanremovetopic.asp

hope it helps !!!

:D
 
I havent had much luck with the checking/removing constraints still. If i were to resort back to the "reset" option for the dataset, do you have any words of wisdom in that arena? I found an issue similar to mine on another board, but i wonder if this would work for me if it were "adapted" to VB???

**********
I have a global dataset object ds that is populated by using
ds.readXml(fileName) in a procedure, then bound to a Windows.Forms.DataGrid.
Everything is OK so far. The data shows on the dataGrid. But the second time
the same procedure is called, nothing shows up on the dataGrid and no error
messages. Everytime, before the dataset is popluated, it is reset by using
ds.reset ( I also did ds.clear(), and ds.Relations.Clear() to make it
cleaner). Also by debugging it, I can see the ds has the same XML string the
second time by using ds.getXml. And if I bind the DataGrid using a copy
like the following:
dataGrid1.SetDataBinding(ds.Copy, "Entry")
Everything is working.

Whats going on here?

(REPLY)
I suspect the data binding is not updated timely after you repopulate the
DataSet. To workaround it, you may refresh the binding with the original
DataSet:

Object source = dataGrid1.DataSource;
dataGrid1.DataSource = null;
dataGrid1.DataSource = source;

I hope this helps you.
***********
 
I was able to get this working using the "copy" method i described above. I am having some dataset update issues, but i dont know if they are related to using the copy method or not. Does anyone know of any issues or reasons why this would be problematic?

Thanks in advance for any advice!! :p
 
hi,
//try a complete wipe out from basics in this order, special !!
dataGrid.DataSource=null;
dataGrid.DataBindings.Clear();
dataGrid.TableStyles.Clear();
datagridtablestype=null;//if any references exist
DataSet=null;// set the main datagrid to null

this worked for me when nothing else did here in this post,
cheers,
craig soens-hughes
dotnet put-an-@-here orange.net
 
Back
Top