Solved

Updating Database using VB.NET Datagrid and Storedprocedure

Posted on 2004-10-11
7
150 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
[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 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

733 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