dataset v dataviews

Is there: Current, Default, Original, Proposed in dataviews identical to datasets?
I was looking for the ability to allow the user to filter and sort data while working with a dataset that does not have to be repopulated by going back to the database when the sort or filter is applied.  And also be able to edit and save changes that eventually go back to the server.
It appears that dataviews are not meant for anything more than viewing?  If I want to view and update I have to use a dataset as opposed to a dataview?  If I use a dataset and wish to filter or sort the dataset by user input I will have to go back to the database with a new query that includes the users filtering or sorting request in the query that then repopulates the dataset?
dastaubAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CodeCruiserCommented:
Actually, each datatable object has a property DefaultView of type DataView. So you can use it like this

dSet.Tables(0).DefaultView.RowFilter = ...

and still make changes in the dataset.
0
dastaubAuthor Commented:
when I use your dSet.Tables(0).DefaultView.RowFilter = ... it works, the data is filtered, but when I sort a datagridview by clicking on a column name, the dataset does not sort with the data on the screen?  
If I access the data by using the below code it shows the data in the order of the original sort order of the query that populated the dataset.

Dim dr As DataRow
        dr = dSet.Tables(0).Rows(DataGridView1.CurrentCellAddress.Y)
        MsgBox(dr(DataGridView1.CurrentCellAddress.X, DataRowVersion.Original).ToString())
0
CodeCruiserCommented:
Is the column of sortable type?
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

dastaubAuthor Commented:
Yes, the column is sortable on the datagridview.  That is why the data no longer matches up with the dataset as the underlying dataset does not get sorted along with what appears on the screen inside the datagridview.
0
CodeCruiserCommented:
How do you set the datasource?

Is the filtering side clear to you now?
0
dastaubAuthor Commented:
 Public con = New SqlConnection("Data Source=INSIGNIA\SQLEXPRESS2;Initial Catalog=AdventureWorks;Integrated Security=True")
    Public sqlDa As New SqlDataAdapter
    Public dSet = New DataSet()
    Public Binder = New BindingSource
    Public command_builder = New SqlCommandBuilder(sqlDa)
    sqlDa.SelectCommand = New SqlCommand("SELECT VendorID,AccountNumber,Name FROM Vendor2", con)
    sqlDa.Fill(dSet, "vendor2")
    Binder.DataSource = dSet.Tables("Vendor2")
    DataGridView1.DataSource = Binder

If i use the below code to access a row in the dataset, it does work until I sort the data then the data is sorted in the datagridview but the underlying dataset remains unsorted.

        Dim dr As DataRow
        dr = dSet.Tables(0).Rows(DataGridView1.CurrentCellAddress.Y)
        MsgBox(dr(DataGridView1.CurrentCellAddress.X, DataRowVersion.Original).ToString())

before you pointed out the dSet.Tables(0).DefaultView.RowFilter = ... I was creating an object of a dataview, but you eliminated that step.



0
CodeCruiserCommented:
Why are you using a binder? Do you access the row after filtering?
0
dastaubAuthor Commented:
Why are you using a binder?
I'm using a binder because I was assuming this makes moving between records easier. As in
Binder.moveprevious()
Binder.movefirst()
Binder.movenext()
Binder.endedit()
I use the binder to populate textboxes and navigate the dataset
Do you access the row after filtering?  If I understand the question, my answer is YES
0
CodeCruiserCommented:
To access filtered rows, use the view instead of the dataset.

>dr = dSet.Tables(0).Rows(DataGridView1.CurrentCellAddress.Y)

Use this instead

dSet.Tables(0).DefaultView.Item(rowindex)
0
Tommy11bCommented:
It appears that dataviews are not meant for anything more than viewing?  If I want to view and update I have to use a dataset as opposed to a dataview?

This is incorrect, if you create a dataview based on a dataset/datatable and change the values within the dataview, you should see the changes reflected back in your dataset
0
dastaubAuthor Commented:
Dim dr As DataRowView
dr = dSet.Tables(0).DefaultView.Item(DataGridView1.CurrentCellAddress.Y)
MsgBox(dr(DataGridView1.CurrentCellAddress.X).ToString())

The above code worked. Previously I had to resort the dataset instead of relying upon a dataview.

The datview does not have the parameters regarding DataRowVersions ?
0
CodeCruiserCommented:
But you can sue the RowVersion property of the DataRowViews in a DataView

http://msdn.microsoft.com/en-us/library/system.data.datarowview.rowversion.aspx
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dastaubAuthor Commented:
thank you for answering multiple questions.
0
CodeCruiserCommented:
Glad to help :-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.