Solved

Best practices using ADO in web forms

Posted on 2011-02-17
3
422 Views
Last Modified: 2012-05-11
Experts,

newbie question.

I am pulling data from a database and populating some text boxes and combo boxes. The users can edit/delete any of these fields. They can enter new data in a control that may have not contained data to begin with.  The data is populated on the Load event. The user can do what they want and then click a "save" button.

What is a good practice to accomplish this?  If the data adapter/data set are created in the Load, then they aren't available in the button_click, correct? Do you create "global" adapters/data sets?
Or
Would you populate the controls using a data reader and then use a command to update the database from the button click?

Any guidance is appreciated.

Thanks in advance.
0
Comment
Question by:jvoconnell
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 400 total points
ID: 34924156
Personally I always use the latter of the two approaches. Mainly because, as you noted, the only way to make use of a DataSet/DataAdapter is to store the huge thing in memory between calls, which is just a waste of resources.

So, the quickest and most convenient option is to populate from a datareader and the write back using a simple command (either a stored procedure or at least parameterised SQL).
0
 
LVL 2

Assisted Solution

by:jondow
jondow earned 100 total points
ID: 34924810
I like to take an OOP approach wherever possible, although if you are only displaying a small amount of data this can be overkill.
Create a class(s) that represents the objects on you page.

Public Class MyObject
    Private _Username As String
    Public Property Username() As String
        Get
            Return _Username
        End Get
        Set(ByVal value As String)
            _Username = value
        End Set
    End Property
End Class


Instance and load the object(s) with your database call (sqldatareader/adapter) prior to displaying on the page:
TBName.Text = MyObject.Username

When posting you page, re-instance your object (either with the existing values if any validation or comparison is needed, or as an empty object) then load your object with the user data:

MyObject.Username= TBName.Text

Then have a update method on your class which you call you update the database

MyObject.Update

This approach lets you apply any business logic (ie validation) from within the property or within the update method.

Hope that helps

Rick
0
 
LVL 1

Author Closing Comment

by:jvoconnell
ID: 34925338
Thank you both for the input. The response by carl_tawn gets me on track for the type of project I'm working on. I wanted to give some credit to jondow as well. I will keep this approach for reference when I do have to work with a large volume of data. Once again, thank you both for your time.
0

Featured Post

Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question