Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
|
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 28th, 2005, 05:54 PM
Friend of Wrox
 
Join Date: Apr 2004
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
Default Updating a Database from a DataView

How do you update a database from a DataView?

I have a dataGrid which is editable, and it's data is based on a dataView. After a user edits a row, and clicks the update button, what is the preferred method for updating the original database using ADO.net?

When my datasource is a dataset, I usually do

da.Update(ds.Tables(0).Select(Nothing, Nothing, DataViewRowState.ModifiedCurrent))

But this doesn't seem to be working for me.

Thanks.

Aaron

 
Old July 29th, 2005, 03:10 AM
Registered User
 
Join Date: Jul 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to sriram6781
Default

I feel that in this scenario you can use DataView.GetChanges that returns a DataTable and using this you can update the Modified records.

 
Old July 30th, 2005, 08:20 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

My preferred method is to hit the database with the necessary update query for the data in question (the single row). Build an update query and call the database with it.

-Peter
 
Old August 1st, 2005, 03:30 PM
Friend of Wrox
 
Join Date: Apr 2004
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi guys,

Thanks for the suggestions.

Sriram: GetChanges is not actually a member of the DataView class.

planoie: This is a great suggestion, and I will actually do it this way for now, but I would love to know why the DataTable underlying my DataView is not seeing the changes I have made to the data in the DataView. Or perhaps my update statement is off.

Here is my full code to update the dataset"

        cnxn.Open()
        Dim cmd As New SqlCommand("SELECT * From ArchiveItems", cnxn)
        Dim da As New SqlDataAdapter
        da.SelectCommand = cmd
        Dim cb As SqlCommandBuilder = New SqlCommandBuilder(da)
            da.Update(ds.Tables("ArchiveItems").Select(Nothing , Nothing, DataViewRowState.ModifiedCurrent))

Reloading the data never shows any of the edits made in the dataView. I think it's a problem with that DataViewRowState property. I've tried it with ModifiedOriginal and CurrentRows as well.

Hope you can help. Thanks.

Aaron

 
Old November 16th, 2008, 06:55 AM
hu_yang
Guest
 
Posts: n/a
Default

you can update dataview like this also :

http://vb.net-informations.com/datav...iew-update.htm

thanks.







Similar Threads
Thread Thread Starter Forum Replies Last Post
Updating database capilleary C# 1 June 28th, 2005 06:03 AM
Help for Updating the database bspradeep Classic ASP Databases 1 May 10th, 2005 03:13 AM
updating database texasraven ASP.NET 1.x and 2.0 Application Design 2 September 21st, 2004 05:14 PM
Updating a database Gary_M Classic ASP Databases 4 November 7th, 2003 11:03 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.