473,394 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Q: Load New Table to DataGrid

Hi,

I have a DataGrid which works. But if I load a new table to the DataGrid, it
will still show those old data I load earlier.

private void loadTableA()
{
if ( openFileDialog.ShowDialog() == DialogResult.OK )
{
this.dataGrid.SetDataBinding(null, null);

try
{
CurrentProject.FileReader fileReader = new
CurrentProject.FileReader();

try // Remove table is already exist in dataSet
{
dataSet.Tables.Remove( "tableA" );
}
catch ( System.ArgumentException )
{
// do nothing
}

dataSet.Tables.Add( fileReader.LoadData( openFileDialog.FileName,
"tableA" ) );

this.dataGrid.SetDataBinding( dataSet, "tableA" );
this.dataGrid.DataSource = dataSet.Tables["tableA"];
this.currencyManager = (CurrencyManager)
this.BindingContext[dataSet.Tables["tableA"]];
}

catch (System.ArgumentOutOfRangeException)
{
MessageBox.Show("Some Message", "Some Caption",
MessageBoxButtons.OK, MessageBoxIcon.Error );
}
}
}
Anyone know where did I do wrong?

Thank you.
--
Soul

Nov 15 '05 #1
1 3500

Hi Soul,

You can set some breakpoint to you application to watch the dataset object,
then
you can find what its internal structure is.

I think the simple way of updating your datagrid to display a new datatable
is
creating a new dataset and bind it to your datagrid.

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| Reply-To: "Soul" <so********@antisocial.com>
| From: "Soul" <no@spam.com>
| Subject: Q: Load New Table to DataGrid
| Date: Wed, 10 Sep 2003 03:41:11 +1000
| Lines: 51
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="utf-8"
| Content-Transfer-Encoding: 7bit
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <um**************@TK2MSFTNGP09.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: dsl-203-113-205-94.vic.netspace.net.au 203.113.205.94
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP09.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:183525
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Hi,
|
| I have a DataGrid which works. But if I load a new table to the DataGrid,
it
| will still show those old data I load earlier.
|
| private void loadTableA()
| {
| if ( openFileDialog.ShowDialog() == DialogResult.OK )
| {
| this.dataGrid.SetDataBinding(null, null);
|
| try
| {
| CurrentProject.FileReader fileReader = new
| CurrentProject.FileReader();
|
| try // Remove table is already exist in dataSet
| {
| dataSet.Tables.Remove( "tableA" );
| }
| catch ( System.ArgumentException )
| {
| // do nothing
| }
|
| dataSet.Tables.Add( fileReader.LoadData(
openFileDialog.FileName,
| "tableA" ) );
|
| this.dataGrid.SetDataBinding( dataSet, "tableA" );
| this.dataGrid.DataSource = dataSet.Tables["tableA"];
| this.currencyManager = (CurrencyManager)
| this.BindingContext[dataSet.Tables["tableA"]];
| }
|
| catch (System.ArgumentOutOfRangeException)
| {
| MessageBox.Show("Some Message", "Some Caption",
| MessageBoxButtons.OK, MessageBoxIcon.Error );
| }
| }
| }
|
|
| Anyone know where did I do wrong?
|
| Thank you.
| --
| Soul
|
|
|
|

Nov 15 '05 #2

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

Similar topics

12
by: Stanley J Mroczek | last post by:
How do you load a dropdownlist when edit is clicked in a datagrid ? <Columns> <asp:BoundColumn DataField="OptionDescription" ItemStyle-Wrap="True" HeaderText="Option...
2
by: duncan | last post by:
Hi I an a mebie to XML / vb.net and I am struggling. I am developing a web base applcation using XML to link to its database so. Here is the XML I want to load into to a datagrid. The...
9
by: John Kirksey | last post by:
I have a page that uses an in-place editable DataGrid that supports sorting and paging. EnableViewState is turned ON. At the top of the page are several search fields that allow the user to filter...
18
by: Julia Hu | last post by:
Hi, I have a datagrid, and in different rows I need to programmatically bind different type of controls and load data into these controls. For example,in the first row I need to bind data into a...
8
by: TM | last post by:
I have a small application that displays records from an access mdb into two datagrids and am looking to see if it is possible to speedup the loadtime somehow. In my formload I am filling my...
2
by: ameen.abdullah | last post by:
Hi Guys, I have a xml file, from which i want a node to be populated in a datagrid. whats the easiest way to do this?? Here is a sample of xml file: <?xml version="1.0" ?> <script...
3
by: ryanbreakspear | last post by:
Hi, I've been doing a bit of reading on the Internet, but can't work out what is the best way to load an XML file into a table. The XML file is normalised, so for each record I create in my...
4
by: =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?= | last post by:
For performance reasons i can not set a sort order on a dataset returned from a stored procedure. Ideally in the sp i'd set the company name as the order and just load the gridview, however the...
1
by: vipbus7 | last post by:
I have one Access database with two files in it - FileA & FILEB. Need to load FileA fields into one datagrid and FileB fields into a different datagrid on the same form with one load tables button...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
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...

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.