Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
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?
Posted

did you try with this:

 

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

Some people are wise and some are other-wise.
Posted
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?
Posted

try to remove constrains with

myTable.Constrains.Clear()

that should help if not post some code please!

:D

Some people are wise and some are other-wise.
Posted
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 i'm probably just going about the order of things incorrectly, as i am a first time coder....but if you do have time, i'd greatly appreciate some help!!! :confused:

form5.txt

Posted

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/default.asp?url=/library/en-us/cpref/html/frlrfsystemdataconstraintcollectionclasscanremovetopic.asp

 

hope it helps !!!

 

:D

Some people are wise and some are other-wise.
Posted

I haven't 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.

 

What's 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.

***********

  • 3 weeks later...
Posted

I was able to get this working using the "copy" method i described above. I am having some dataset update issues, but i don't 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

  • 1 year later...
Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...