Solved

DataGridView: Updating DS after changes

Posted on 2006-11-01
7
509 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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

Technology Partners: 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

Suggested Solutions

Title # Comments Views Activity
How to repeat the data 4 42
VB.net Filesystem watcher not working 5 55
Convert VB web project to C# 3 62
Trying to Create FTP Client in VB.net - getting errors 3 34
This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

739 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