PC Review


Reply
Thread Tools Rate Thread

Refresh Bound DataGrid

 
 
Mark
Guest
Posts: n/a
 
      15th May 2008
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
 
Reply With Quote
 
 
 
 
Cor Ligthert[MVP]
Guest
Posts: n/a
 
      15th May 2008
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" <(E-Mail Removed)> schreef in bericht
news:BE5AC72E-77C7-49EF-AE98-(E-Mail Removed)...
> 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


 
Reply With Quote
 
Mark
Guest
Posts: n/a
 
      15th May 2008
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" <(E-Mail Removed)> schreef in bericht
> news:BE5AC72E-77C7-49EF-AE98-(E-Mail Removed)...
> > 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

>

 
Reply With Quote
 
Cor Ligthert[MVP]
Guest
Posts: n/a
 
      15th May 2008
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" <(E-Mail Removed)> schreef in bericht
news:9426E17F-5C96-4E43-AFD3-(E-Mail Removed)...
> 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" <(E-Mail Removed)> schreef in bericht
>> news:BE5AC72E-77C7-49EF-AE98-(E-Mail Removed)...
>> > 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

>>


 
Reply With Quote
 
Mark
Guest
Posts: n/a
 
      15th May 2008
Cor -

Thanks for your comments.

Mark

"Cor Ligthert[MVP]" wrote:

> 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" <(E-Mail Removed)> schreef in bericht
> news:9426E17F-5C96-4E43-AFD3-(E-Mail Removed)...
> > 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" <(E-Mail Removed)> schreef in bericht
> >> news:BE5AC72E-77C7-49EF-AE98-(E-Mail Removed)...
> >> > 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
> >>

>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Bound/Unbound? Refresh or not? Faster?.... The Dude Microsoft Access Form Coding 2 17th Jan 2009 12:19 PM
Array bound to Datagrid - getting values out of the datagrid g.o.atkins@gmail.com Microsoft ASP .NET 1 14th Sep 2006 02:00 PM
refresh from DataGridView to bound DataSet roybrew@att.net Microsoft ADO .NET 9 16th Aug 2006 12:15 AM
Record Added to Bound Datagrid on Refresh Jim Bayers Microsoft ASP .NET 1 14th Oct 2004 07:26 PM
Auto-refresh bound list box Pat Randall Microsoft Access Form Coding 1 6th Nov 2003 03:47 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:15 PM.