Solved

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

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 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

24 Experts available now in Live!

Get 1:1 Help Now