trying to modify my dataset

G

Guest

Hi. I've been trying to modify my dataset and have been unsucessful. Any
help would be great.
What I have is a dataset in a session variable. Here is what I have done to
stored into the dataset via store procedure.

Sample Stored Procedure:

CREATE PROCEDURE prcGetData
AS

SELECT id1, id2, current_name FROM test_table
GO

Sample test_table:

id1 id2 current_name
--- --- ------------
1 1 john
1 2 mary
1 3 dave


Somewhere in my web form, user will be presented with the dataset in a grid
format. When a user selects a row, a popup window appears and user can
modify that row. I now want to update, delete or even insert a new row back
to the dataset, stored in session and later commit all my changes, regardless
of update, delete, or insert back to my original table (test_table). I have
try to do this and I'm getting an error "Table does not have a primary key".
Well, I kind of understand why this error occurs but, how do I solve this
matter of updating a particular row or even a different method then the once
I'm using.

Here is a sample code:

Dim _dsDataSetTestTable As DataSet = Session("dsGetTestTable")
Dim myTable As DataTable
Dim myRow As DataRow
Dim myColumn As DataColumn
Dim adapter As New SqlDataAdapter
Dim PrimarKey(1) As Object
PrimarKey(0) = "1" 'Request.form("id1")
PrimarKey(1) = "1" 'Request.form("id2")

For Each myTable In _dsDataSetTestTable.Tables
For Each myRow In myTable.Rows
myRow = myTable.Rows.Find(PrimarKey) '** So, I can find the row I want to
update, delete....
myRow.BeginEdit()
myRow("current_name") = "Tom" '** update row 1's current_name from "john"
to "Tom"
myRow.EndEdit()
adapter.Update(_dsDataSetVsam1)
Session("dsGetTestTable") = _dsDataSetTestTable
Next myRow
Next myTable

Additionally, if I can get some help on insert a new record into my dataset,
that will be great. And finally, I haven't start this yet because of my
current problem but, any example of how I can update my "modified" dataset
back to my original table. Thanks in advance.

Henry
 
G

Guest

You may want to try using AcceptChanges on the dataset, or debugging the code
and examining the table to see if the status of the rows are changing when
you delete them.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top