473,842 Members | 1,573 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.S etDataBinding(n ull, null);

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

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

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

this.dataGrid.S etDataBinding( dataSet, "tableA" );
this.dataGrid.D ataSource = dataSet.Tables["tableA"];
this.currencyMa nager = (CurrencyManage r)
this.BindingCon text[dataSet.Tables["tableA"]];
}

catch (System.Argumen tOutOfRangeExce ption)
{
MessageBox.Show ("Some Message", "Some Caption",
MessageBoxButto ns.OK, MessageBoxIcon. Error );
}
}
}
Anyone know where did I do wrong?

Thank you.
--
Soul

Nov 15 '05 #1
1 3518

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********@ant isocial.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.publi c.dotnet.langua ges.csharp
| NNTP-Posting-Host: dsl-203-113-205-94.vic.netspace .net.au 203.113.205.94
| Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP09.phx.g bl
| Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.csharp:1835 25
| X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.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.S etDataBinding(n ull, null);
|
| try
| {
| CurrentProject. FileReader fileReader = new
| CurrentProject. FileReader();
|
| try // Remove table is already exist in dataSet
| {
| dataSet.Tables. Remove( "tableA" );
| }
| catch ( System.Argument Exception )
| {
| // do nothing
| }
|
| dataSet.Tables. Add( fileReader.Load Data(
openFileDialog. FileName,
| "tableA" ) );
|
| this.dataGrid.S etDataBinding( dataSet, "tableA" );
| this.dataGrid.D ataSource = dataSet.Tables["tableA"];
| this.currencyMa nager = (CurrencyManage r)
| this.BindingCon text[dataSet.Tables["tableA"]];
| }
|
| catch (System.Argumen tOutOfRangeExce ption)
| {
| MessageBox.Show ("Some Message", "Some Caption",
| MessageBoxButto ns.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
2816
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 Description"></asp:BoundColumn> <asp:TemplateColumn runat="server" HeaderText="Id Type Option" "> <itemtemplate> <asp:label runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "TypeOption") %>' /> <asp:label runat="server" ID="LlbTypeOption" Visible=False...
2
11540
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 datagrid has the number of columns specified and is ready and waiting for its data. <Users>
9
21653
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 the results in the grid. Say you filter the grid for records that have a certain condition set to "NO" (in this case a checkbox). In this scenario the search returns one result. If I then check the checkbox ("YES") and save it, I now get my message...
18
2474
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 textbox, and in the second row I need to bind data into a dropdownlist...It all depends on the data I select from the database. I cannot use TemplateColumn because it has to be the same type of control for one column.
8
1589
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 dataset and binding it to the datagrids. Is there a better place to get my grids loaded and speed up the program loadtime ? Thanks --
2
1685
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 version="1.1"> <jobs>
3
2840
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 database table, I'll need to grab data from the nodes above. e.g. <sex>
4
10929
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 joins are very complicated and this causes the sp to take 20 time (at least) longer than when no ordering is specified. I would create a temp table and sort this for the return, however, ado.net can not see a temp table because it does not exist at...
1
1256
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 on the form. When I created the datagrids FileA-TableA & FileB-TableB were loaded and show on an *.*XSD tab in the project I am working on. There is also an additional table that showed up called ProjectTableAdapter. I am not sure what this is for...
0
9715
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10945
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
9454
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...
1
7859
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7040
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
5697
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...
0
5886
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4500
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4090
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.