Solved

Editing with - "DataView" in Visual Basic.NET 2003 !!

Posted on 2007-11-18
3
577 Views
Last Modified: 2013-11-26
Hi,

I have the following code:

    Imports System.Data
    Imports System.Data.SqlClient

    Dim Cn As SqlConnection
    Dim Da As SqlDataAdapter
    Dim Ds As DataSet
    Dim Dv As DataView
    Dim Cb As SqlCommandBuilder

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Cn = New SqlConnection("Server=(local);Database=Sample;Trusted_Connection=yes")
        Cn.Open()
        Da = New SqlDataAdapter("Select * from Emp", Cn)
        Ds = New DataSet
        Cb = New SqlCommandBuilder(Da)
        Da.Fill(Ds, "Emp")
        Dv = Ds.Tables("Emp").DefaultView
        DataGrid1.DataSource = Ds.Tables("Emp")
    End Sub

    Private Sub btnFilter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFilter.Click
        Dv.RowFilter = "Salary * 5 <= 15000"
    End Sub

    Private Sub btnSort_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSort.Click
        Dv.Sort = "Salary DESC"
    End Sub

    Private Sub btnSaveSubset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveSubset.Click
        'TO DO: Update and Save subset of data - after filtering
    End Sub

Can you please provide me the code at "TO DO:" ?

Thanks
0
Comment
Question by:kishore_peddi
  • 2
3 Comments
 
LVL 41

Expert Comment

by:graye
ID: 20310053
It'd be as simple as:

     Da.Update(Ds)

Take a look at the following, you might find it useful:  http://home.hot.rr.com/graye/Articles/SavingDataADO.htm
0
 

Author Comment

by:kishore_peddi
ID: 20310307
How DataView will be used to EDIT changes and SAVE changes here in this example ? I am not using Dv....am i correct ? Please correct me if i am wrong !!
0
 
LVL 41

Accepted Solution

by:
graye earned 500 total points
ID: 20311938
The DataGrid itself can be responsible for the editing... it can allow a user to change an existing row, add a new row, and delete an existing row.   So, you don't have to write any code to make that happen... it's all part of the DataGrid.  (Er, well... you might have to adjust the properties that turn on/off the control's editing, adding, and deleteling)

These changes are "cached" in the underlying DataSet.   So, that all you have to do to save those changes is use the DataAdapter's Update() method.

Did you take a look at the examples in that link... it's pretty much on track as to what you're talking about
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now