Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2007-11-18
3
Medium Priority
?
604 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 2000 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

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Integration Management Part 2
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

972 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