开发者

Reading & Writing in asp.net

开发者 https://www.devze.com 2023-01-26 04:23 出处:网络
I have a basic page which has fields that I read from the database and write to it. I would like to know where I should call the insert and read commands. I know about age_load but heard about page_lo

I have a basic page which has fields that I read from the database and write to it. I would like to know where I should call the insert and read commands. I know about age_load but heard about page_loadcomplete.

I noted that when the user refreshes the page, for some reason the sqldatasource loads the old da开发者_如何转开发ta(before the write) even though new data has been loaded on the form.

thanks,

Jim


Let me segregate first your inquiries per paragraph and give some comments.

  1. For your question where to insert or read commands, I would usually call my insert/read commands in another project/class file. However, these commands are triggered in my user interface. That means, if I have to retrieve my records to view them, I would setup my read commands in my Data Access Project/Class then trigger them in my user interface once it loads my page. Or, if I will insert new records, I will set a method to insert up in my class project/class file then call it in my user interface.

  2. How often does this happen? I haven't encountered this since. It's usually that once you inserted/updated a data, the datasource refreshes itself.


It's important that you understand the ASP.NET page life cycle (assuming that you're using web forms). With this you'll know the correct page events to use and their particular purpose. Page_Load and Page_OnLoadComplete are not used to save changes to data, but rather retrieval and rendering of that data.

I would have the generic database calls inside a database class. The fields in I would place into a separate class, and this class would have an associated mapping class containing the particular CRUD methods you need (eg the names of Stored Procedures to call, Parameters etc). I'd pass this to an instance of the database class to perform the functions I want, triggered by an event from the page (eg a Button_Click event).

On your second point, refreshing the page calls a HTTP GET, so your page will be reloaded. This to me implies that your write is not actually occurring, check the database to ensure that it is.

0

精彩评论

暂无评论...
验证码 换一张
取 消