Re: How do you clear a datatable?

Tech-Archive recommends: Fix windows errors by optimizing your registry



If you want to remove all of the data in the table in the database, you
need to use a DELETE query. ("DELETE FROM myTable" will do it.)

Good luck.
Robin S.
------------------------
"Tony Girgenti" <tony(nospam)@lakesideos.com> wrote in message
news:uuW1srKaHHA.3272@xxxxxxxxxxxxxxxxxxxxxxx
Hello pvd.

Thanks for your reply. I understand now where the data is at different
points in my program. I was confused about DataTables in the dataset as
opposed to tables in the database.

I need to use a DELETE query to initialize the table in the database.
Right?

Thanks,
Tony

"pvdg42" <pvdg42@xxxxxxxxxxxxxxxxx> wrote in message
news:OWrJ6EKaHHA.3584@xxxxxxxxxxxxxxxxxxxxxxx

"Tony Girgenti" <tony(nospam)@lakesideos.com> wrote in message
news:%23eEEQaDaHHA.4872@xxxxxxxxxxxxxxxxxxxxxxx
Hello Bill.

I am absolutely perplexed and frustated by this whole dataset/database
concept. I thought i understood it, but now i'm totally confused.

I thought a dataset was supposed to be disconnected from the physical
database.

When i look at a datatable properties in the dataset designer, it
defines it as the Items DataTable. If i right click on the Items
DataTable in the Dataset designer and select Preview Data..., and click
on the Preview button, it shows all of the rows. So if i did a
itemsDataBase.Clear, why is the data still there?

When i look at the database in Server Explorer, right click on the
Items table there and click Show Table Data, it shows the same data.

I'm sure that you know way more than i do about this stuff, but i just
don't get it.

Thanks,
Tony

Everything you say about DataTable objects is correct, except for what
happens when you look at DataTable contents in the Dataset Designer.
When you preview data in the designer, the fill() method associated with
the DataTable object executes to show you what the DataTable *will* hold
when filled in your application when it runs. If you execute the Clear()
method in your application, after filling the DataTable, all rows in the
DataTable will be deleted.

Bill has already pointed out that none of the above has any effect on
the actual database table, so when you access the preview from Data
Designer after executing your program, the DataTable is *refilled* with
the same data (from the database) as before.

To test the effects of Clear(), add some code to your app to access the
Count property of your DataTable's DataRowCollection, after Clear
executes.

http://msdn2.microsoft.com/en-us/library/system.data.datarowcollection_members.aspx





.


Quantcast