|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
DataTable and DataGridViewI'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?? :-( 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?? :-( Earl wrote:
> Use ds.Tables.Remove("noname") Thanks for your suggestion, but it doesn't help! :-(> > There's a good example in the 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. 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. -- Show quoteMiha Markic [MVP C#] RightHand .NET consulting & development www.rthand.com Blog: http://cs.rthand.com/blogs/blog_with_righthand/ "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?? :-( Using of
ds.Reset(); or ds.Tables.Remove("noname"); doesn't works! Any Suggestions? :-( Are you sure that new table your are adding has a different name?
Did you check ds.Tables.Count after Reset? -- Show quoteMiha Markic [MVP C#] RightHand .NET consulting & development www.rthand.com Blog: http://cs.rthand.com/blogs/blog_with_righthand/ "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? :-( Miha Markic [MVP C#] ÐÉÛÅÔ:
> Are you sure that new table your are adding has a different name? I do ds.Reset() - and I'm really switched to my original state (without > Did you check ds.Tables.Count after Reset? > 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 :-( 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 :-( |
|||||||||||||||||||||||