Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ADO - DataViews

Status
Not open for further replies.

netangel

Programmer
Feb 7, 2002
124
PT
My app uses a datatable to send some session data between pages.
This data table has info about several variables that are present in all pages, and I need them to be persistent when the user returns to the page.
Datatable structure:
Page Val1 Val2 Val3
1 a a a
1 b c a
2 x y z
3 m n o
3 m n o

Each page might need to up to 3 rows of data. I have more than 50 different pages. I cant save data on a database.

How can I use a datatable / dataview to
- delete all rows from a page,
- insert n rows to a page or
- filter all rows from a page?

NetAngel
 
To delete:
invoke .delete() method on the particular row you want to delete:
dataTable.rows.delete();

To Insert:
invoke the .newRow() method on the datatable, targeting a new datarow object. You can then populate that datarow, and then insert it back into the datatable:
DataRow r;
r = DataTable.NewRow();
//populate r values
DataTable.Rows.Insert(0,r);

To Filter,
invoke the .RowFilter() method on the DataView object with a valid piece of SQL. Here's a link to a good help file on your hard drive (just paste it into the help):
ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemdatadataviewclassrowfiltertopic.htm

Check out the docs for more information on the other methods, as well.

DataTable (along with it's big brother, the dataset) is an extremely useful and powerful tool. It's basically an in memory lightweight relational database (like Access or something) capable of many of the same things. Very nice stuff.

good luck! :)
paul
penny1.gif
penny1.gif

The answer to getting answered -- faq855-2992
 
Thanks, but I've worked arround without dataviews. I had never seen the 'select' method of the datatable, and it was exactly what I needed.

In my oppinion, dataviews are useless, unless you want to bind something to them. To work with data using code, the best way is to use datatables.

I've never been able to use dataviews in my applications, and believe I've been using .NET for almost two years.
NetAngel
 
DataViews can be useful if you need to sort data in an existing DataTable.

Say, for instance, you use the extended DataGrid from faq855-2026 and you want to use the sorting feature w/o having to go back to the database... well, you can just persist the datatable (perhaps in xml) over post backs and onSort, you apply the sort expression to a dataview derived from the datatable, whereas you can't sort the datatable directly, so you'd have to return to the database with a query w/ an ORDER BY clause if you don't use a dataview.

You can also use them to apply filters w/o actually deleting rows. These filters can include filters on columns and/or rowstates.

Certainly not as useful as a DataTable, but they do have their place.

-paul
penny1.gif
penny1.gif

The answer to getting answered -- faq855-2992
 
As I said in my previous message, I found the 'select' method. I allows, not only to filter data, but also to order it, without going back to the database.

The only use the dataview may have is to control the original, updated and deleted records.
NetAngel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top