473,394 Members | 1,658 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.

How to clear old data from a DataGridView and a DataSet?

As an exercise in learning Visual Basic 2005, I am putting together a simple
XML editor.

I place on the form the objects DataGridView1 and DataSet1.

' Read an XML file into DataSet1:
DataSet1.ReadXml("BIRDS.XML")

' Bind the DataGridView to the DataSet:
DataGridView1.DataSource = DataSet1

' Having determined that the TableName of the
' DataTable I am interested in is "bird",
' make this the DataMember of the DataGridView:

DataGridView1.DataMember = "bird"

' Set up autogeneration of columns:
DataGridView1.AutoGenerateColumns = True

And now the contents of the file appear in the grid for viewing and editing.
OK so far.

But now I want to load in a new file. When I load "MUSICIANS.XML", with its
DataMember "musician", the existing data from "BIRDS.XML" is not
overwritten. It either remains as it is within the grid and the MUSICIANS
data fails to appear, or, depending on the structure of the new file, the
new data may be appended to the existing data. The number of columns and
their headings remain what they were instead of reflecting the structure of
the new file.

Obviously I need some way of re-initializing the DataSet or the DataGridView
or both before loading a new file. I have been able to do this only by
re-instantiating the DataSet on each pass:

Dim DataSet1 As New DataSet

This gets rid of all previous data and I can load different files in
succession. But it's not a good solution because instantiating the DataSet
within a Sub means, I assume, that it won't be visible to other routines
that I'll need for saving data back to a file. And it's probably bad for
other reasons too.

I tried setting
DataGridView1.DataSource = Nothing

but this didn't work.

So can anyone tell me how to re-initialize the DataSet and/or the
DataGridView so that I can load new files cleanly? I couldn't find anything
in the documentation. (If there is an explanation somewhere, please point me
to it.)

Thanks.
David
Dec 30 '06 #1
0 1781

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

Similar topics

1
by: Chuck Gantz | last post by:
I have an existing XML file that I read into a data set ds. The XML is hierarchical; i.e., it looks like <A> <B> <C> <D> element1<\D> <E> element2<\E> <\C> <C>
15
by: philip | last post by:
On a form, I have a datagridview. This datagridview is constructed on a dataset filled by a tableadapter. The table adapter do very well what it must do when filling dataset. Insertions,...
2
by: Andy | last post by:
I have a C# application that is using a DataGridView (DGV). The DGV uses a table adapter to connect to the datasource, which uses a DataSet as the data. The DataSet has some constraints placed on...
2
by: Rick Shaw | last post by:
Hi, I have a problem with the datagridview not refreshed when the application first appear on the screen. The datagridview display data from a table in the dataset. At the same time, I've added...
6
by: alexia.bee | last post by:
Hi all, I am new to C# so please bear me :). I have an app which uses datagridview. it has 8 columns. I also have struct which has 8 members(the same as the datagridview). when I add row to...
2
by: ysidro | last post by:
this is maby a answer and not a discussion. I saw many questions about how to clear an unbound datagrid in C#. Here is de ansuer: " dataGridView1.Rows.Clear(); "//clear or delete all columns in...
1
by: weird0 | last post by:
How can i update the data in my database directly through datagridview....? Can anyone tell me the appropriate links and what is the exact event in datagridview that handles it and some explanation...
4
by: =?Utf-8?B?UmludSBHb3BhbGFrcmlzaG5hIFBpbGxhaQ==?= | last post by:
Hi All, I have an application that fetch data thru a store proc and display in a datagrid, but after successful execution of proc the data grid is not visible.Please go thru the following code...
1
by: Amit | last post by:
Hello , Is there any way i can import data from datagrid to sqlserver. please advise . thanks & Regards
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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.