472,956 Members | 2,638 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,956 software developers and data experts.

How to Refresh Datagrid Control?

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
Jun 27 '08 #1
6 5371
Hi

I think you first have to reload the DataSet,
the grid will refresh automaticaly when DataSet is changed.

Frank
"Mark" wrote:
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
Jun 27 '08 #2
Frank -

Would you suggest the code that I need to use to "refresh" the dataset?

I'm at a loss.

Thanks,
Mark

"Frank Uray" wrote:
Hi

I think you first have to reload the DataSet,
the grid will refresh automaticaly when DataSet is changed.

Frank
"Mark" wrote:
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
Jun 27 '08 #3
Hi Mark

I do not know your code ...
Normaly you would fill a grid like this:

**************

// Variables
public System.Data.SqlClient.SqlConnection return_SQLNATIVEConnection = new
System.Data.SqlClient.SqlConnection();

// Create Connection
return_SQLNATIVEConnection.ConnectionString = "Data
Source=SQLServer\SQLInstance;Initial Catalog=SQLDatabase;Integrated
Security=SSPI;";
return_SQLNATIVEConnection.Open();

// DataAdapter erstellen
System.Data.SqlClient.SqlDataAdapter local_DataAdapter = new
System.Data.SqlClient.SqlDataAdapter("SELECT * FROM Table",
return_SQLNATIVEConnection);

// DataSet erstellen
System.Data.DataSet local_DataSet = new System.Data.DataSet();

// DataSet füllen
local_DataAdapter.SelectCommand.CommandTimeout = 0
local_DataAdapter.Fill(local_DataSet, "DataSetTableName");

// Grid füllen
this.YourDataGrid.DataSource = local_DataSet

**************

For reload/refresh just run this code.

Best regards
Frank

"Mark" wrote:
Frank -

Would you suggest the code that I need to use to "refresh" the dataset?

I'm at a loss.

Thanks,
Mark

"Frank Uray" wrote:
Hi

I think you first have to reload the DataSet,
the grid will refresh automaticaly when DataSet is changed.

Frank
"Mark" wrote:
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
Jun 27 '08 #4
Frank -

Thanks for the code. I can use this (and probably will end up using it if I
can't figure it out (see below)).

In my initial question I mentioned that I used the Add New Data Source
wizard. This process created the connection and a typed dataset for me
without any coding from me at all --- which is great and nice. It seems to
me that I should be able to refresh the dataset somehow, leveraging the code
generated by the wizard.

For example, soemthing like this (which doesn't work) would be great.
local_Dataset.clear();
local_Dataset.mydatatableTableAdaptor.GetData();

So yeah I can use the code you supplied but then I wonder why I bothered
using the wizard in the first place.

Again, thanks for your suggestions.

Mark



"Frank Uray" wrote:
Hi Mark

I do not know your code ...
Normaly you would fill a grid like this:

**************

// Variables
public System.Data.SqlClient.SqlConnection return_SQLNATIVEConnection = new
System.Data.SqlClient.SqlConnection();

// Create Connection
return_SQLNATIVEConnection.ConnectionString = "Data
Source=SQLServer\SQLInstance;Initial Catalog=SQLDatabase;Integrated
Security=SSPI;";
return_SQLNATIVEConnection.Open();

// DataAdapter erstellen
System.Data.SqlClient.SqlDataAdapter local_DataAdapter = new
System.Data.SqlClient.SqlDataAdapter("SELECT * FROM Table",
return_SQLNATIVEConnection);

// DataSet erstellen
System.Data.DataSet local_DataSet = new System.Data.DataSet();

// DataSet füllen
local_DataAdapter.SelectCommand.CommandTimeout = 0
local_DataAdapter.Fill(local_DataSet, "DataSetTableName");

// Grid füllen
this.YourDataGrid.DataSource = local_DataSet

**************

For reload/refresh just run this code.

Best regards
Frank

"Mark" wrote:
Frank -

Would you suggest the code that I need to use to "refresh" the dataset?

I'm at a loss.

Thanks,
Mark

"Frank Uray" wrote:
Hi
>
I think you first have to reload the DataSet,
the grid will refresh automaticaly when DataSet is changed.
>
Frank
>
>
"Mark" wrote:
>
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
Jun 27 '08 #5
Hi Mark

Well, the wizard also just creates some code.
This code is possibly stored in FormXY.Designer.cs.
And it works, when you open the form, the data is upToDate.

Because a DataSet is something like a snapshot,
"this.YourGridView.Refresh()" is not working ...
It is refreshing against the DataSet and this is still the same.
You first have to bring your DataSet UpToDate.

Or you start using some external (not MS) components.
I use Infragistics for all grid applications. Makes life easyer ... :-))

Regards
Frank

Jun 27 '08 #6
Frank -

Thanks for your comments.

The following code did the trick [i.e., requeried the sql db]:
this.mytableTableAdapter.Fill(this.myDataset.mytab le);

In fact I had something like this yesterday but it did not work. In reality
it was working but I didn't think it was since something else wasn't
working... When I went back to a simple model "Fill" worked just fine, and I
was able to work around that something else.

Again thanks for your interest.

Mark


"Frank Uray" wrote:
Hi Mark

Well, the wizard also just creates some code.
This code is possibly stored in FormXY.Designer.cs.
And it works, when you open the form, the data is upToDate.

Because a DataSet is something like a snapshot,
"this.YourGridView.Refresh()" is not working ...
It is refreshing against the DataSet and this is still the same.
You first have to bring your DataSet UpToDate.

Or you start using some external (not MS) components.
I use Infragistics for all grid applications. Makes life easyer ... :-))

Regards
Frank
Jun 27 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Cat | last post by:
If you have a datagrid with an underlying dataset and rows are added to the dataset during a program run, how do you get the datagrid to update itself to repflect the changes in the underlying...
1
by: James | last post by:
I have a data grid refresh problem. I have a few columns and the first column is data in the form of numbers. And in the form of the data grid if I specify for example something like a code(in a...
0
by: Marcus | last post by:
Hello! I'm buildning a webpage in ASP.NET using Visual Basic. The page contains a datagrid, a dropdownlist, some textboxes and a couple of buttons. The datagrid displays barcodes from a table...
3
by: IGotYourDotNet | last post by:
Is it possible to only refresh a control such as a datagrid without refreshing the entire page? I have 2 datagrids on my page and i only need to refresh 1 of them and if possible i do not want...
7
by: Juan Romero | last post by:
Hey guys, please HELP I am going nuts with the datagrid control. I cannot get the damn control to refresh. I am using soap to get information from a web service. I have an XML writer output...
10
by: jaYPee | last post by:
I have a function that call a stored procedure which performs an insert command. now i want to refresh the dataset so that the newly inserted data will be available to my datagrid I have tried...
2
by: Dan | last post by:
Hi, I have a Datagrid in a simple form that I programmatically modify using something like that : Me.DataGrid1(RowID, ColID) = "blablabla" But my cell wont refresh unless I click on another...
3
by: David Cartwright | last post by:
Hi all, I'm having a weird time with a call to the Refresh() method of a DataGridView. I have a VB.NET 2005 Windows application with a main form and a "worker" thread. The main form delegates a...
5
by: vai | last post by:
i'm working in visual basic. i want to dispaly the records in a datagrid control who's data source is adodc.i want to display the records for a particular date. i.e. if the date which i accept...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.