Cor Ligthert [MVP]
5/15/2008 4:13:00 PM
Mark,
I assume that this is a windows form datagrid as you wrote.
Assume that you do this somewhere.
dataGrid.DataSource = dataTable;
dataTable = new DataTable();
Then your dataGrid will show forever the old datatable, which will not be
disposed whatever you do until you do again.
dataGrid.Datasource = dataTable;
Cor
"Mark" <Mark@discussions.microsoft.com> schreef in bericht
news:9426E17F-5C96-4E43-AFD3-FEB1EE244C42@microsoft.com...
> Cor -
>
> Could you suggest some actual code?
>
> Given that the wizard has generated all of the code to do the connection,
> create the dataset bind the control to the dataset (not to mention my lack
> of
> expertise with ado.net) I'm at a loss for the code.
>
> Thanks again for your comments and help.
>
> Mark
>
> "Cor Ligthert[MVP]" wrote:
>
>> Mark,
>>
>> As I see this problem then it is mostly that there is created a new
>> datasource, while an old one is still active because there is a
>> reference.
>>
>> As this is the fact, then clear that datasource instead of creating a new
>> one.
>>
>> Cor
>>
>> "Mark" <Mark@discussions.microsoft.com> schreef in bericht
>> news:BE5AC72E-77C7-49EF-AE98-2AB3996B572D@microsoft.com...
>> > Hi -
>> >
>> > I'm having trouble refreshing a datagrid control bound to a dataset
>> > that
>> > was
>> > created from the New Data Source wizard. What is the code required to
>> > refresh the datagrid with data from the data source (sql db)?
>> >
>> > More Details:
>> >
>> > The application is C# Windows (VS 2005).
>> >
>> > I used the "Add New Data Source" wizard to connect to a sql database
>> > and
>> > select the tables to include in the in-memory dataset.
>> >
>> > From the Data Source window, I selected a table, designated it as a
>> > datagrid
>> > and then dragged it onto the form. So far so good. The form runs
>> > fine,
>> > the
>> > data grid populates properly.
>> >
>> > Now I want to refresh the datagrid control. (I know the sql db has
>> > updated
>> > (values changed, new records inserted), after the form was started.) I
>> > have
>> > added a button to the form (named "Refresh Grid") and want to add code
>> > to
>> > it's click event to do the refreshing. My question is what is the code
>> > that
>> > is needed to requery the sql database?
>> >
>> > Thanks for your suggestions.
>> > Mark
>>