jbcedge
jbcedge

Reputation: 19505

FormView_ItemUpdating in not updating

I am using a FormView to update an existing SQL Server record. The rows from the sqldatasource display fine in the FormView and I can edit them. When I click Update, I get the ItemUpdating event but not the ItemUpdated event and the revisions are not written to the database.

Can anyone help me in this please.

Upvotes: 1

Views: 1020

Answers (3)

Matt V
Matt V

Reputation: 41

In your ItemUpdating event handler, make sure of the following things:

-If you are not using optimistic concurrency checking, remove any old values the FormView may be placing in the OldValues collection.

-Make sure that all of the parameters required by your stored procedure, query, or data source have values and are named correctly in either the Keys or NewValues collections (and make sure that no duplicates exist).

In some cases (usually when an ObjectDataSource is involved), I've had to override the values set by the FormView control, by doing something like this:

protected void myFormView_ItemUpdating(object sender, FormViewUpdateEventArgs e)
    {

        // remove the old values
        e.Keys.Clear();
        e.OldValues.Clear();
        e.NewValues.Clear();

        // set the parameter for the key
        e.Keys.Add("@key", valueGoesHere);

        // set other parameters
        e.NewValues.Add("@param1", aValue);
        e.NewValues.Add("@param2", anotherValue);
    }

It's not pretty, but it give you absolute control over what gets passed to the DataSource. Generally you should not have to do this if the controls in your FormView are all bound using Bind() for two-way databinding (instead of Eval), but at the very least you could put a break point in ItemUpdating and open up the e.Keys, e.OldValues, and e.NewValues collections to see if the contents are what you expected.

A next step would be to launch SQL Server Profiler to run a trace and examine the actual query being performed.

Upvotes: 1

Solmead
Solmead

Reputation: 4199

Can we see what the sqldatasource looks like? Did you remember to put all the parameters in the sqldatasource under the insert and update parameters list?

Oh also are you setting the cancel property at all in the itemupdating event?

Upvotes: 0

ine
ine

Reputation: 14084

If you take out the ItemUpdating event and the ItemUpdated event, does your SQL statement execute without errors?

If so, why don't you post some of the code you are using?

Upvotes: 0

Related Questions