473,698 Members | 2,234 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5417
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.Sql Client.SqlConne ction return_SQLNATIV EConnection = new
System.Data.Sql Client.SqlConne ction();

// Create Connection
return_SQLNATIV EConnection.Con nectionString = "Data
Source=SQLServe r\SQLInstance;I nitial Catalog=SQLData base;Integrated
Security=SSPI;" ;
return_SQLNATIV EConnection.Ope n();

// DataAdapter erstellen
System.Data.Sql Client.SqlDataA dapter local_DataAdapt er = new
System.Data.Sql Client.SqlDataA dapter("SELECT * FROM Table",
return_SQLNATIV EConnection);

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

// DataSet füllen
local_DataAdapt er.SelectComman d.CommandTimeou t = 0
local_DataAdapt er.Fill(local_D ataSet, "DataSetTableNa me");

// Grid füllen
this.YourDataGr id.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.c lear();
local_Dataset.m ydatatableTable Adaptor.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.Sql Client.SqlConne ction return_SQLNATIV EConnection = new
System.Data.Sql Client.SqlConne ction();

// Create Connection
return_SQLNATIV EConnection.Con nectionString = "Data
Source=SQLServe r\SQLInstance;I nitial Catalog=SQLData base;Integrated
Security=SSPI;" ;
return_SQLNATIV EConnection.Ope n();

// DataAdapter erstellen
System.Data.Sql Client.SqlDataA dapter local_DataAdapt er = new
System.Data.Sql Client.SqlDataA dapter("SELECT * FROM Table",
return_SQLNATIV EConnection);

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

// DataSet füllen
local_DataAdapt er.SelectComman d.CommandTimeou t = 0
local_DataAdapt er.Fill(local_D ataSet, "DataSetTableNa me");

// Grid füllen
this.YourDataGr id.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.YourGridV iew.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.mytableTab leAdapter.Fill( this.myDataset. mytable);

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.YourGridV iew.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
5035
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 dataset? I've tried Update() and Refresh() but these don't seem to work. Only thing that works is rebinding the datset to the datagrid control, but this doesn't seem to be quite right. Cat
1
6276
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 text box) the column of numbers should change colors depending on whether the number was in the specified code(if it belongs to the code, color the cell (first column) in Red and if not in some other color). It all works out fine until I scroll...
0
1982
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 in a database (Sql Server 2000). I want to automatic update the datagrid when new new posts arrives in the table. Before the datagird is updated, the choosen index from the
3
1708
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 to refresh the entire page since there is alot of data on the page. can that be done or no?
7
15440
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 the file to a folder, and then I read it back into the dataset using the dataset1.readxml. Up to this point, everything works wonderfully. The query executes, the dataset gets populated, and I get the results displayed in the datagrid.
10
30675
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 to call DsStudentCourse1.Tables("SchYrSemCourseJoin").Clear() SqlDataAdapter3.Fill(DsStudentCourse1) However, the fill method causes a lot of time to process.
2
4565
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 cell or move the scrollbar of the datagrid... :(
3
7562
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 Sub to the worker so that the latter can refresh the DataGrid after updating the DataTable driving it. When I run the app under the debugger, everything's fine. But when I run it for real, it hangs, apparently in the Refresh() method of the...
5
9402
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 from the user exists,then for that particular date all the records must be displayed. my problem is when i run my form all the records are displayed. the records ,which are in my access database table. so i set the following properties, ...
0
8674
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9028
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8861
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7728
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4369
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2330
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.