Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / ADO.NET / May 2008

Tip: Looking for answers? Try searching our database.

Refresh Bound DataGrid

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mark - 15 May 2008 05:10 GMT
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
Cor Ligthert[MVP] - 15 May 2008 05:36 GMT
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

> Hi -
>
[quoted text clipped - 26 lines]
> Thanks for your suggestions.
> Mark
Mark - 15 May 2008 14:15 GMT
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

> Mark,
>
[quoted text clipped - 36 lines]
> > Thanks for your suggestions.
> > Mark
Cor Ligthert[MVP] - 15 May 2008 17:12 GMT
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

> Cor -
>
[quoted text clipped - 55 lines]
>> > Thanks for your suggestions.
>> > Mark
Mark - 15 May 2008 18:29 GMT
Cor -

Thanks for your comments.

Mark

> Mark,
>
[quoted text clipped - 71 lines]
> >> > Thanks for your suggestions.
> >> > Mark

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.