Solved

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

Posted on 2007-11-18
3
590 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

751 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