Home All Groups Group Topic Archive Search About

DataTable and DataGridView

Author
8 Jan 2006 5:35 PM
Ilya Dyoshin
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?? :-(

Author
8 Jan 2006 7:58 PM
Earl
Use ds.Tables.Remove("noname")

There's a good example in the Help.

Show quote
"Ilya Dyoshin" <zip***@mail.ru> wrote in message
news:dpriq7$8sk$1@news.univ.kiev.ua...
> 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?? :-(
Author
9 Jan 2006 5:36 AM
Ilya Dyoshin
Earl wrote:
> 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.
Author
8 Jan 2006 8:00 PM
Miha Markic [MVP C#]
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.

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Show quote
"Ilya Dyoshin" <zip***@mail.ru> wrote in message
news:dpriq7$8sk$1@news.univ.kiev.ua...
> 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?? :-(
Author
9 Jan 2006 5:41 AM
Ilya Dyoshin
Using of
ds.Reset();

or

ds.Tables.Remove("noname");

doesn't works!

Any Suggestions? :-(
Author
9 Jan 2006 9:47 AM
Miha Markic [MVP C#]
Are you sure that new table your are adding has a different name?
Did you check ds.Tables.Count after Reset?

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Show quote
"Ilya Dyoshin" <zip***@mail.ru> wrote in message
news:dpstbn$klk$1@news.univ.kiev.ua...
> Using of
> ds.Reset();
>
> or
>
> ds.Tables.Remove("noname");
>
> doesn't works!
>
> Any Suggestions? :-(
Author
10 Jan 2006 1:12 PM
Ilya Dyoshin
Miha Markic [MVP C#] ÐÉÛÅÔ:
> 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 :-(
Author
10 Jan 2006 8:41 PM
Ilya Dyoshin
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.

Ilya Dyoshin wrote:
Show quote
> Miha Markic [MVP C#] ÐÉÛÅÔ:
>
>> 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 :-(
Author
9 Jan 2006 4:09 PM
Jesus Lopez
Is your application an ASP.NET app ? Are you forgetting to call
dataGridView.DataBind ? are you putting the code in "if not ispostpack"
statement?

AddThis Social Bookmark Button