Solved

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

Posted on 2007-11-18
3
583 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
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 …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

770 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