473,396 Members | 1,992 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

trying to modify my dataset

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
Nov 19 '05 #1
1 2903
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.

"Henry" wrote:
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

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

51
by: Richard Hengeveld | last post by:
Hi all, I'm trying to understand how pointers for function parameters work. As I understand it, if you got a function like: void f(int *i) { *i = 0; }
6
by: Babu Mannaravalappil | last post by:
Can somebody please help me figure out why the following method exceptions out? Execution at the line marked with ********** hangs for about 15 seconds and then I get an error that says an...
4
by: Frank Rizzo | last post by:
Hello. Every now and then (it's rare), i get an exception when calling SqlDataAdapter.Fill. The code is calling a stored procedure and attempts to stuff the results into a dataset. It yields the...
12
by: Dica | last post by:
i can't seem to find a way to cast the value in my comboBox to integer. i've tried the following: short iProjectID = Convert.ToInt16(cboProjects.SelectedValue); i keep getting a "Sepcified...
0
by: AndyAFCW | last post by:
I am developing my first .NET application that connects to a SQL Server 2000 database and I am having a total nightmare :x :evil: I am running Windows 2000 with Visual Studio .NET version...
5
by: Allan A via DotNetMonster.com | last post by:
I have a xml document created <?xml version="1.0" standalone="yes" ?> <Group> <Information> <ID>44</ID> <Detail>Hello World</Detail> </Information> <Information> <ID>45</ID> <Detail>My...
12
by: Gary Paris | last post by:
I have enclosed the sample code that I created. I want to read in employee data, and modify a few fields. I have tried to globally declare the objects that I need but I still am having problems. ...
3
by: Will Chamberlain | last post by:
I am running into a strange error when I try debugging my current application. A form loads up with a dynamically-populated textbox full of software titles. Upon selection of a software title and...
0
by: Patrick | last post by:
Hello, I want to modify an existing XML-File based on Input in a Form. I used a DataSet to load the XML File with the ReadXml method. I then displayed the relevant entries via the GetChildRows...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.