Simple form postback to update a database

  • Thread starter Thread starter Ray Valenti
  • Start date Start date
R

Ray Valenti

In a .Net Asp application I am able to retrieve data from an Access db and
display in on a web form. How ever during the update function after a page
update, the update command does not throw an exception but it does not save
out the changes either. It seems that upon the postback no data exists in
the dataset. I must be missing something.

How you post the data from an edited user page back to the database?


if (!(Page.IsPostBack))
{
this.oleDbDAUser.Fill(this.dsMain1,"Users");
this.lblUserID.DataBind();
this.txtFirstName.DataBind();
this.txtMiddleName.DataBind();

..........

}



No error here, but no data is saved either:


private void btnSave_Click(object sender, System.EventArgs e)
{
try
{
this.oleDbDAUser.Update(this.dsMain1);
}
catch (Exception oops)
{
this.txtUserMessage.Text = "Error occured!<BR>" + oops.ToString() ;
}

}
}

Thanks,
Ray

--
 
Microsoft has come along way with ASP.NET but it is still
stateless. Remember that once the page posts, your
variables for the dataset is gone. You can cache the
dataset and then update the dataset and thus the data on
a postback, or if you are using a DataGrid/DataList you
can look at returning the DataSource property. Otherwise,
you will have to reconstruct the data each time you need
to hit the database. Let me know if you need more
specifics.

- Rob
 
Back
Top