Saving an updated dataset back to the database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Creini
    New Member
    • Aug 2008
    • 1

    Saving an updated dataset back to the database

    Hi,

    I'm trying to write a Webapplication in ASP.Net 3.5 and C#.

    I read data from a database and Bind it to a FormView using

    Code:
    <%# Eval("Columname") %>
    Which works quite well. But I have no idea how to save the changes back to the database. Well, I think I can use the dataadapter.upd ate function, but I don't know how to call it before my page does a postback and loose all my changes.

    How do I save things back to a database??

    Thanks,
    Mattias
  • Curtis Rutland
    Recognized Expert Specialist
    • Apr 2008
    • 3264

    #2
    Ok, well if you are doing your binding in your codefile's Page_Load method, make sure that you surround it with
    Code:
    if(! Page.IsPostBack)
    {
    //here's where your binding goes
    //this is C#, but you get the picture
    }
    That will prevent your changes from being lost on postback.

    You need to make sure that your DataAdapter has a Update and (possibly) an Insert command. You can automatically generate these commands using a CommandBuilder.

    Take a look at this article to see an example of the CommandBuilders .

    Then you should be able to use the Update command.

    Comment

    Working...