There is a problem:
I'm writting a client for use with various ODBC drivers.
There is a function:
System::Data::DataTable ^buildTable(System::String ^sqlQuery)
which builds new instance of DataTable based on the results of sqlQuery.
The table name is "noname".
Then I'm adding this DataTable to DataSet ^ds like
ds->Tables->Add(buildTable("some query"));
Then I'm linking my DataGridView object to this table:
dataGridView1->DataSource = ds;
dataGridView1->DataMember = "noname";
and this works well.
Unlikely, when I'm trying to build another view from another sqlQuery
there is a problem:
//Before adding new samenamed-tables I'm deleting all tables
while (ds->Tables->Count)
ds->Tables->RemoveAt(ds->Tables->Count - 1);
And table is really removed from DataSource (I've watched that). And
then I run again
ds->Tables->Add(buildTable("another query"));
dataGridView1->DataSource = ds;
dataGridView1->DataMember = "noname";
And I see table "noname" actually wasn't deleted... it's still in the
memory! and I can't see another results, but only the first.
Any suggestions?? :-(
Earl - 08 Jan 2006 19:58 GMT
Use ds.Tables.Remove("noname")
There's a good example in the Help.
> There is a problem:
>
[quoted text clipped - 36 lines]
>
> Any suggestions?? :-(
Ilya Dyoshin - 09 Jan 2006 05:36 GMT
> Use ds.Tables.Remove("noname")
>
> There's a good example in the Help.
Thanks for your suggestion, but it doesn't help! :-(
I tried as ds.Tables.Remove("noname") as well as
ds.Tables.RemoveAt(ds->Tables->Count -1 ) but none of them bring me
correct result.
Miha Markic [MVP C#] - 08 Jan 2006 20:00 GMT
Hi Ilya,
Perhaps the newly added table has the same name?
Btw, there is a method DataSet.Reset that will remove the tables for you.
Or, just create another instance of dataset.

Signature
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/
> There is a problem:
>
[quoted text clipped - 36 lines]
>
> Any suggestions?? :-(
Ilya Dyoshin - 09 Jan 2006 05:41 GMT
Using of
ds.Reset();
or
ds.Tables.Remove("noname");
doesn't works!
Any Suggestions? :-(
Miha Markic [MVP C#] - 09 Jan 2006 09:47 GMT
Are you sure that new table your are adding has a different name?
Did you check ds.Tables.Count after Reset?

Signature
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/
> Using of
> ds.Reset();
[quoted text clipped - 6 lines]
>
> Any Suggestions? :-(
Ilya Dyoshin - 10 Jan 2006 13:12 GMT
> Are you sure that new table your are adding has a different name?
> Did you check ds.Tables.Count after Reset?
I do ds.Reset() - and I'm really switched to my original state (without
any table).
then I'm adding the same-named table from a new instance.
Because adding always new tables will result in huge amount of operating
memory for this application :-(
Ilya Dyoshin - 10 Jan 2006 20:41 GMT
Hi all!
I've solved my problem, probably a bit awkward.
Maybe somebody can help me with more mutual code.
before add same-named table into DataSet ds.Reset() doesn't work. So I'm
just deleting out of memory my DataSet and then build it again..
delete ds;
ds = gcnew System::Data::DataSet();
and this works well (as I wished :) And memory doesn't grow up.
But nevertheless I think such method is unsafe, and there is more exact
solution for this problem. Maybe someone has solved this problem.
>> Are you sure that new table your are adding has a different name?
>> Did you check ds.Tables.Count after Reset?
[quoted text clipped - 5 lines]
> Because adding always new tables will result in huge amount of operating
> memory for this application :-(
Jesus Lopez - 09 Jan 2006 16:09 GMT
Is your application an ASP.NET app ? Are you forgetting to call
dataGridView.DataBind ? are you putting the code in "if not ispostpack"
statement?