?
Solved

Updating Database using VB.NET Datagrid and Storedprocedure

Posted on 2004-10-11
7
Medium Priority
?
152 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 750 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

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month15 days, 10 hours left to enroll

741 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