Solved

Updating Database using VB.NET Datagrid and Storedprocedure

Posted on 2004-10-11
7
145 Views
Last Modified: 2010-04-23
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
Comment
Question by:anwarmir
  • 3
  • 2
  • 2
7 Comments
 
LVL 28

Expert Comment

by:iboutchkine
ID: 12277990
If you are using dataadapter then you can

Dim cb As New OleDbCommandBuilder(da)
 da.Update(ds, "MyTable")
0
 

Author Comment

by:anwarmir
ID: 12278023
But that only updates the dataadapter. How can I update each updatedrow in the grid be updated to the database
0
 
LVL 28

Expert Comment

by:iboutchkine
ID: 12278169
Your dg is bound to the datatable. Every update in dg will be reflected in the dt. Dataadapter will update the underlying table
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 10

Expert Comment

by:Hans Langer
ID: 12278497
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
 

Author Comment

by:anwarmir
ID: 12295753
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
 
LVL 10

Expert Comment

by:Hans Langer
ID: 12297185
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
 
LVL 10

Accepted Solution

by:
Hans Langer earned 250 total points
ID: 12297255
The dataset look for property RowState of its DataTable.Rows and he update only de row they are changed state.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

747 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now