Updating Dataset

R

Richard

Hi

I am new to ASP.NET and I'm trying to follow the following MSDN
Walkthrough
(http://msdn.microsoft.com/library/d...ughusingdatagridwebcontroltoreadwritedata.asp)
regarding datagrids and pushing and pulling data from a database.
I am using an Oracle database with a larger table, but otherwise I am
following the walkthrough exactly. Everything is working properly
except for when I update the data set. I am unable to call a 'find'
method that the walkthrough claims should have been generated
automatically:

// Finds the row in the dataset table that matches the
// one the user updated in the grid. This example uses a
// special Find method defined for the typed dataset, which
// returns a reference to the row.
dsCategories.CategoriesRow r;
r = dsCategories1.Categories.FindByCategoryID(int.Parse(key));

The program complains that the FindByCateogryID method is not present
and so the program is unable to update the dataset. I have checked the
Categories class and there is no method that looks remotely close to
the FindByCategoryID method.
Can anyone help me?

Thanks
 
A

arunprakashb

Hi,
Can you verify if the CategoryID is the primary column in your
database table? If it is not, that could be the problem. One option is
to set the primary column in the table and regenerate the dataset.

Thanks.
Arun Prakash. B
 
R

Richard

Thanks Arun!

The method is now showing up and the web app is now compiling properly.
However, I started getting an error from this line:

// Calls a SQL statement to update the database from the dataset
oracleDataAdapter1.Update(dataSet11);

The error I recieved was as follows:
InvalidOperationException: Update requires a valid UpdateCommand when
passed DataRow collection with modified rows

I was able to fix it by adding the following line before the Update
command:

System.Data.OracleClient.OracleCommandBuilder cmd = new
System.Data.OracleClient.OracleCommandBuilder(oracleDataAdapter1);

And it is updating without generating any errors, however it is
shifting the data one row to the left every time it updates. For
example a row would look like this:
1 2 3 4 5 6 7
And after clicking on edit and then update without changing any cells
the row would look like this:
2 3 4 5 6 7 7

Anyone know how I can fix this?
Thanks
 
R

Richard

Figured it out...

I was copying the wrong cells, the MSDN walkthrough code had an extra
read only column at the beggining that I didn't.

Thanks again for your help Arun.
 

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

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,097
Latest member
RayE496148

Latest Threads

Top