Solved

DataGridView: Updating DS after changes

Posted on 2006-11-01
7
512 Views
Last Modified: 2008-02-26
Hello. I'm working with Datagridview, loading and binding to a dataset created on the fly.

        Public Function CropMasterSelect(ByVal WhereClause As String) As DataSet
            With cmd
                .Connection = con
                .CommandText = "admCropMasterSEL"
                .Parameters.Clear()
                .Parameters.AddWithValue("@WhereClause", WhereClause)
                .CommandType = CommandType.StoredProcedure
            End With
            da.SelectCommand = cmd
            ds.Tables.Clear()
            da.Fill(ds)
            Return ds

        End Function

        Me.DataGridView1.DataSource = db.CropMasterSelect(CreateWhereClause).Tables(0)
        Me.DataGridView1.Columns(0).Visible = False

My question is, after changes have been made in DataGridView by the user, how do I update those records back to the database?  Can I somehow use the dataset that was created on the fly?  Any code examples would be helpful.

Regards,
ADWooley
0
Comment
Question by:adwooley2
[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
  • 3
  • 2
  • 2
7 Comments
 
LVL 10

Accepted Solution

by:
ericwong27 earned 300 total points
ID: 17848278

       ' Retrieve source data
        Dim lDataTable As DataTable = CropMasterSelect(WhereClause).Table(0)
        lDataTable.AcceptChanges()

        ' Assume data has bee change
        lDataTable.Rows(0)(1) = "xxx"

        ' Update the changes
        For Each lRows As DataRow In lDataTable.GetChanges.Rows
            ' Write a code to update the changed
        Next
0
 
LVL 5

Expert Comment

by:DEEPESH
ID: 17848763
Its all about AcCeptChanges, this command will save bach changes to Database.
http://msdn2.microsoft.com/en-gb/library/system.data.dataset.acceptchanges.aspx
0
 
LVL 10

Expert Comment

by:ericwong27
ID: 17848856
Hi, DEEPESH

AcceptChanges just commit the change on dataset but not in database. To update the data on database need to use DataAdapter.Update(ds) but since store procedure is used is not applicable here.



0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 5

Expert Comment

by:DEEPESH
ID: 17849087
Hmmm
Sorry EricWong27 I forget to mention the Update command, but in this kind of scenario I think we have to make an seprate  update query and update database
0
 

Author Comment

by:adwooley2
ID: 17854627
Thanks for your comments.
Eric, I can't use DataAdapter.Update(ds) when using a stored procedure? I am forced to iterate through the datarows and update with changes one by one?
0
 
LVL 10

Expert Comment

by:ericwong27
ID: 17856158
Yes ... DataAdapter.Update(ds) has some limitation, you should not use store procedure, make a query from more then 1 table and etc
0
 

Author Comment

by:adwooley2
ID: 17856166
Eric,
Thanks.  I did solve my problem.  However, I'm having another related problem.  
I posted a new question:  Datagridview - update problems

If you can help me, I would be appreciative.
Regards,
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

696 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