• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 156
  • Last Modified:

Updating Database using VB.NET Datagrid and Storedprocedure

Hello I am Populating a datagrid by binding a DataView to the the Datagrid. The Dataview is built from Storedprocedure Query.
Can anyone tell me how can I propogate the changes in the datagrid back to the database. I am assuming the user may of chaged values in multiple rows of the datagrid.

Below is a snippet of code that binds the SP results to the datagrid.

Many Thanks


Dim oShowcode As Object
        Dim oShowyear As Object
        Dim oStartdate As Object
        Dim oEnddate As Object
        Dim oerror As Object
        Dim oBatch As Object

        Dim mydatatable As New DataTable
        mydatatable = myConnection.ArSPExecReturnDataTable("PrsgDocumentrequestbatchAdmin", oShowcode, oShowyear)
        'mydataset.Tables.Add(mydatatable)
        Dim mydataset As New DataSet
        Dim mydataview As DataView = New DataView(mydatatable)

        mydataset = mydatatable.DataSet
        mydataset.Tables(0).TableName = "results"

        MyDataGrid.DataSource = mydataview
0
anwarmir
Asked:
anwarmir
  • 3
  • 2
  • 2
1 Solution
 
iboutchkineCommented:
If you are using dataadapter then you can

Dim cb As New OleDbCommandBuilder(da)
 da.Update(ds, "MyTable")
0
 
anwarmirAuthor Commented:
But that only updates the dataadapter. How can I update each updatedrow in the grid be updated to the database
0
 
iboutchkineCommented:
Your dg is bound to the datatable. Every update in dg will be reflected in the dt. Dataadapter will update the underlying table
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
Hans LangerCommented:
Hi,
You can see DataAdapter.UpdateCommand  property in this article, maybe that help you,

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconupdatingdatabasewithdataadapterdataset.asp

Good Luck
0
 
anwarmirAuthor Commented:
Thanks...But I have just one more question are you saying that although I populated  the datagrid with a storedprocedure. Any changes to the Dataadapter.Datagrid will automatically take place. I would not have to write a Storedprocedure which Updates the database. The thing that confuses me is how does the datagrid know which table to update ?

Thanks
0
 
Hans LangerCommented:
You must define Storedprocedure that Update the database.

The datagrid is binded to the dataset and the dataset know how to update the data source.
0
 
Hans LangerCommented:
The dataset look for property RowState of its DataTable.Rows and he update only de row they are changed state.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now