Response.redirect

Last post 02-23-2007 8:47 AM by wibblet. 2 replies.

Sort Posts:

  • Response.redirect

    02-23-2007, 8:04 AM
    • Loading...
    • wibblet
    • Joined on 01-20-2007, 11:31 AM
    • London
    • Posts 22

    I've got a problem when adding data to the database.  I'm using a wizard and have written the data set on the page behind. 

    When adding data to the incident table, the final part of the code looks like this:

     

    //Create the command builder

     

    OleDbCommandBuilder cb = new OleDbCommandBuilder(adaptor);

     

    //retrieve an updated table adaptor

    adaptor = cb.DataAdapter;

     

    //update the database using the dataset

    con.Open();

     

     

    //Response.Redirect("Finishrecord.aspx");

    added = adaptor.Update(dsIncident,

    "tblincident");

    Response.Write(added.ToString() +

    " records added");

    }

     

    catch (Exception err)

    {

    Response.Write(

    "Error adding record");

    Response.Write(err.Message);

    }

     

    finally

    {

    con.Close();

    }

     

    I put this line in

    Response.Write(added.ToString() + " records added");

     In the development phase, to check the database was updating.  What I really want to happen is to redirect to another page, hence the commented out

    Response.Redirect("Finishrecord.aspx");

    What appears to be happening is as soon as I put this line in, the database ceases to update, but if I comment it out it works fine.  So I've fiddled around with where this line should go, but nothing seems to work.  I'm sure it's simple enough, but I'm just not seeing it.

     Please could somebody point out to me where I'm being such an idiot?

  • Re: Response.redirect

    02-23-2007, 8:28 AM
    Answer
    • Loading...
    • SGWellens
    • Joined on 01-02-2007, 4:27 PM
    • MN, USA
    • Posts 3,026
    • Moderator
      TrustedFriends-MVPs
    //Response.Redirect("Finishrecord.aspx");

    added = adaptor.Update(dsIncident,

     

    If you uncomment the line above, your page will redirect BEFORE the Update statement.

    You could change the order of statements or try:

    Response.Redirect("Finishrecord.aspx", false);  // do not terminate current page before redirecting.

    Steve Wellens
  • Re: Response.redirect

    02-23-2007, 8:47 AM
    • Loading...
    • wibblet
    • Joined on 01-20-2007, 11:31 AM
    • London
    • Posts 22

    Thanks.  I had tried moving the line around as I thought that was problem.

     

    The Response.Redirect("Finishrecord.aspx", false); worked fine. Yes

Page 1 of 1 (3 items)
Microsoft Communities
Page view counter