15 Great ASP.NET 2.0 Data Tutorials Published

Earlier this year I posted two long data access tutorial posts.  My goal was to then follow up these popular posts (90,000+ views and counting!) with a whole series around them.  Unfortunately work sidetracked me and I found I didn't have the time to-do them justice...

Thankfully Scott Mitchell kindly offered to help write them instead, and has put together an awesome data access tutorial series that is now online here under the "Learn" tab of the http://www.asp.net website.  15 of the data tutorial segments can now be read online, with another 25 still on their way.  Each of the tutorials is available in both VB and C#, and in both HTML and PDF format.  Full source code is also provided for all samples.

The data series begins by creating a DAL using the built-in data TableAdapter designer in Visual Web Developer Express and Visual Studio.  Scott then create a business class layer that encapsulates the DAL and adds additional business logic and validation to it.  All of the samples then use the ASP.NET 2.0 ObjectDataSource control to bind against the business class layer, and show how to perform common binding operations against it.  Note that if you want you can easily substitute the table adapter DAL for your own DAL implementation with the business class layer -- all of the 39 other data tutorials will then work against it the same way.

The list of currently published data articles in the series includes:

Introduction Articles

  • Creating a Data Access Layer using Typed DataSets
  • Creating a Business Logic Layer
  • Using Master Pages and Site Navigation for Consistent Look and Feel of the Data Samples

Basic ASP.NET Data Reporting

  • Displaying Data with the ObjectDataSource
  • Using ObjectDataSource Declarative Parmeters
  • Programmatically Setting ObjectDataSource Parameter Values

Master/Detail Reporting

  • Master/Detail Filtering with a DropDownList Control
  • Master/Detail Filtering with two DropDownList Controls
  • Master/Detail Filtering across two pages
  • Master/Detail Using a Selectable Master GridView with a Details DetailView

Custom Formatting

  • Custom Formatting Based Upon Data
  • Using TemplateFields in a Gridview Control
  • Using TemplateFields in a DetailsView Control
  • Using the FormView's templates
  • Displaying Summary Information in a GridView's Footer

Check out all of these great tutorials on the www.asp.net site here

Over the next few weeks 25+ more tutorials will appear covering paging, sorting, editing, deleting, validation and much, much more.

Hope this helps,

Scott

 

48 Comments

  • Yes They Are great.

    Eagerly Waitng For the remaing to be listed.

  • Thanks Scott !!! In one word: AWESOME !!!

    Very useful for me and my friends.



    Regards

  • This is one of the best resources for using data in ASP.Net.



    Scott(s), you guys are the best! ;)

  • Thank you Scott. Really it is more easy to build seriouse remoute business application by asp.net (especially 2.0) now. I suppose sometime that it is more profit to develop the new application by asp.net then spend a lot of time to study all possabile ways to use objects in big billing systems. And main thing is now that the developing of 3-tier architecture of web applications are pretty easy now by asp.net 2.0. Thanks a lot again for all your examples. Sincerely, LukCAD

  • Hi Nandu,

    If you look in the top right hand corner of the data tutorials page above, you'll see links to download multiple samples zip'd up together.

    Hope this helps,

    Scott

  • Scott, I stumbled across an introduction you had blogged about to the System.Net.Mail class and had a question for you Googling has not resolved for me. In all the examples, including yours, the body of the emails are one liners. But what happens when you want to send a text email (not html) and its actually a full email? How does one create formatting like one can in an email client (e.g. indentation, paragraphs, etc.)? I've looked over the MSDN documentation to no avail. Any help in this area would be appreciated. David.

  • hi sir , plz let me ask you i want to start asp.net 2.0 am i have to study asp.net 1.0 first then study asp.net 2.0 ? or how can i study it ? thanks a lot and i hope you answer me . phphtm@yahoo.com

  • Hi David,

    For sending mail, the HTML formatting option will give you the most styling flexibility.

    With the regular text option, you can probably just add standard text line break characters to cause a line break, and then use tab characters or spaces for indentation.

    Hope this helps,

    Scott

  • Hi Phphtm,

    You don't need to study ASP.NET 1.0 before learning ASP.NET 2.0. There are a ton of resources out there that can help you start immediately just using ASP.NET 2.0.

    The http://www.asp.net web-site is the best place to get started -- it then links to a ton of good content elsewhere.

    Hope this helps,

    Scott

  • Hi Agrinei,



       It is really intersting one! - Good work. Keep it up!



    ~ Smith

  • Silly question about these data tutorials: does the ObjectDataSource re-query the database at each postback? I can tell its Selecting and Selected events fire each time.

  • Hi Scott great articles , I have considered your blog as a Bible ...I have a question though can you post(or are there any plans in future to post) some articles or tutorials in Design Patterns. Thanks.

  • Hi Sriram,

    Glad you like my blog! :-)

    Can you be more specific about what design patterns you are looking for posts on?

    Thanks,

    Scott

  • Hi Flip,

    By default the ObjectDataSource requiries on each request. You can optionally enable data caching if you want to cache the data on the middle-tier for multiple client uses though.

    Hope this helps,

    Scott

  • These tutorials are great

  • Hi Scott, Since ADO.NET 2.0 has already come up with abstract classes like DBCommand and DBconnection  I would like to see some examples on abstract and Factory Patterns(I am like a novice in though.) Thank You very much...

  • Scott,
    I have read many of your articles and would like to say thank you for all of the education you have provided me.
    I am a ASP.NET C# and VB.NET developer and I am curious about developing the different layers? I have been developing with .NET since 1.1 and have always developed sites utillizing NameSpacing for the different layers
    CompanyName.AppName.Layer
    Solution = MyBiz.MyApp
    MyBiz.MyApp.WebUi
    MyBiz.MyApp.Data
    MyBiz.MyApp.Core
    MyBiz.MyApp.Rules
    etc. etc.
    Do you still recommend using this technique or is it over engineering the software?

  • Hi Moojjoo,

    For large projects I think separating our your functionality into namespaces like that makes a lot of sense. It helps keep things organized and logical, and so is a good best practice.

    Hope this helps,

    Scott

  • Hi Scott,

    Since ADO.NET 2.0 has already come up with abstract classes like DBCommand and DBconnection  I would like to see some examples on abstract and Factory Patterns

  • Scott,

    These tutorials are the best I have come across when researching ASP.NET 2.0's new features. Have found them really easy to understand and follow. Awesome!

    Just wondering when we can expect the remaining tutorials to be posted. Keen to complete the picture on updating the database, concurrency issues, etc.

    Cheers,

    Dan.

  • Hi Dan,

    The next set should come out either later this week or early next week. We are looking to release them in chunks -- about every 2 weeks from now on.

    Hope this helps,

    Scott

  • This is excellent. Please continue the good work.

  • Hi Scott,
    These tutorials are great and enable the developpers to focalize on the real business process.
    But, would you recommend this kind of architecture (GridView / BLL / DAL with typed dataset) in an B2C Web apllication like e-commerce with several thousands users connected at the same time ?
    Even, would you only recommend a DAL with typed dataset in that conditions ?
    Thanks for your blog.

  • Hi DDD,

    Yep -- this approach should work well in a B2C scenario. It will scale very well.

    Hope this helps,

    Scott

  • Hi Peter,

    When a DataSet is used within a class library or Windows client project, the connection-string is stored within an App.Config file. The format of this file is the same as Web.config -- and so when you compile the assembly and reference it from a web app you just want to make sure the connectionstring section in the web.config file has the same values as the one in app.config.

    My guess is that the problems you are running into have something to-do with porting existing dataset code form the app_code folder to this class library. Have you tried creating a new dataset class in a class library to sanity-check that that is working?

    Thanks,

    Scott

  • Hey Scott,
    This section on tutorials for data usage is great, but I'm looking for some more information on WHY you would use certain things - I guess more from a design perspective.  
    I've always used Datareaders in my applications for example.  Currently, I used them to load up a custom valueobject in the DAL, and pass that back to be used as an ObjectDataSource.  I've alwyas read and believed this is better from a performance perspective.  However, stongly-typed datasets may make my life simpler from a development side.
    I guess what I'm looking for are architecture/application design decisions on when to use what.  Patterns/best practices /pros and cons etc for each one.  I've been to Microsoft's patterns and practices site, and use things like the enterprise library, but haven't found any definitive "use this or use that" in certain scenarios comparisons.  I'm probably missing it somewhere, since it seems to me like a common question.  Any help or thoughts would be appreciated.  
    Thx

  • Scott, I cut this from a post on the asp.net UI forum and no one has responded, I wonder if you experience the unexpected deleting of data described below:


    We have a pretty extensive framework that we have built. Our update and insert methods on our business objects accept a data entity object that represents an entire row in the DB. Our insert and update stored procedures have parameters for all of the fields in the row.

    It would be unthinkable to create a new method on the BizObject, a new method on the DataAccessObject and new stored procedures for every form that we build using these controls.

    Can you tell me if this is by design or by bad design or a bug?

    Current Behavior as I see it:

    The ObjectDataSource retrieves a DataEntityObject representing a row (with 7 fields) in the DB by the GetByID() method on the BizObject. It then passes the DataEntityObject to the DetailsView control who is responsible for managing the modification of (5 of the 7 fields) in the row . When the DetailsView update link is clicked, the row(5 fields) is returned to the ObjectDataSource control who then calls the update method on the BizObject. The ObjectDataSource then creates a new data entity object with 7 fields and populates 5 of them and sends it back to the DB via the BizObject's update method, thus wiping out the 2 fields that were not included in the DetailsView.

    The ObjectDataSource should not do what was described in the previous paragraph but should do one of the following.

    Store the original DataEntityObject (with 7 fields) and populate the 5 fields that have been updated, thus preserving the 2 fields with sensitive data not shown in the DetailsView on this particular aspx page.

    Retrieve a DataEntityObject from the DB with the BizObject's GetByID() method (with 7 fields) and populate the 5 fields that have been updated, thus preserving the 2 fields with sensitive data not shown in the DetailsView on this particular aspx page.

    It would be foolish to think the control would behave any other way.

    Let me know what you think.

  • Hi Terence,

    Sorry for the delay in getting back to you on this (I'm just catching up on comments now).

    The reason those two fields aren't being displayed is because they probably aren't visible on the DetailsView. In cases like those, you want to explictly add their column names to the DataKeyNames collection -- which will cause the values to be preserved, and enable the DataEntityObject to be populated with them when the update occurs.

    Hope this helps,

    Scott

  • Hi Scott,

    In your reply to Peter's post you mentioned that a DataSet in a separate class library creates the connection string in the app.config file. However, it also creates a settings.settings file, and seems to be grabbing the connection string from there (and that resource is pre-compiled if I'm not mistaken). The connection string created in app.config looks like this:

    Data.Properties.Settings.MyConnectionString

    and even deleting it from the app.config file doesn't prevent the DataSet from successfully connecting using the string found in settings.settings (It is not even using ConfigurationManager in the generated code)

    The only way I found to enable the DataSet to grab the connection string using the ConfigurationManager was to create the DataSet and then manually editing the XSD file to force using the right class. However this method completely disables further manipulation of the DataSet in the designer.

    Am I missing something here?

    Best,

    Yuval

  • Hi Yuval,

    The Settings class should check the web.config file first, and then only fall back to use the default one used at development time if that value isn't there.

    If you aren't seeing this behavior, can you zip up a simple sample that shows the problem and send it to me? I'll then loop some folks in.

    I suspect the problem you are having might be that you don't have the exact same connectionstring name in your app.config file and web.config file for the web application.

    Hope this helps,

    Scott

  • Hi George,

    Unfortunately I don't know of any formal case-studies that have been done yet on this.

    Sorry!

    Scott

  • Great tutorials! I am a newbie, so perhaps this is a dumb question... I don't want to bind my ObjectDataSource to a web control. Instead, I want to iterate through the results returned via the ObjectDataSource and perform some action based on the results. For instance, perform a calculation across all the returned records. How do I go about this?

    Thanks!

  • Hi Steven,

    There are a couple of ways you could do this. Probably the easiest would be to just instantiate your data access code or component directly, rather than using an ObjectDataSource to call it. This way you can do whatever you want with the return value result.

    Hope this helps,

    Scott

  • Scott, the tutorials are great but I have a question. I posted this in the ASP.NET forums but have not had a decent response.

    In a GridView, if you use AutoGenerateColumns="false" the HeaderText property for a BoundField is not picked up from the datasource (in this case an ObjectDataSource returning DataTables). So the only thing to do is set the HeaderText property manually. If I am building a multi-lingual application this is no good. You can't use in the HeaderText property because BoundField does not have a Databinding event. So what is one to do?

  • Hi Todd,

    If you can send me email (scottgu@microsoft.com) I can try and put you in touch with someone who can help.

    Thanks,

    Scott

  • im also newbie to asp.net 2. can you post a tutorial on how we can separate the dal from the bll on 2 different class. im having a problem doing that. thanks.

  • Hi Earl,

    Here is a pointer to a great set of tutorials that show how to split the DAL and BLL into two separate classes: http://www.asp.net/learn/dataaccess/default.aspx?tabid=63

    Hope this helps,

    Scott

  • Hi scott,
    thanks, but now I'm try to create a class for DAL and a class for BLL and compile them into two separate class(WWPersonDAL.dll and WWPersonBLL.dll). Any tips and steps on doing this? Or links to get me started? Thanks again.

  • Hi Earl,

    You should be able to create two class library projects and split up the work across them (just have the BLL library reference the DAL library).

    What you'll then want to-do is to make sure the web.config file inside your web application has the same connection string value as in the app.config file of your DAL library. That way it will resolve the connection string reference correctly at runtime.

    Hope this helps,

    Scott

  • What if you use the VS2005 designer to create all of your tableAdapters and tables, and then you need to change the data-access methodology so that you use the DABB provided via the Enterprise Library? Is a developer required to edit the generated code (that would most likely get overwritten if the IDE is used to make any changes?)? Is there an easy/global way to make this change?

  • Thanks Scott, it is very helpful.

  • any chance that this Data Tutorials would be show how to add a localization/globalize option to the site?? thanks

  • In this site you can find good examples and tutorials: www.dotnetspace.com


  • please help me to find the solution

  • Hi Scott,

    I'm developing an order form which have order header and order detail like the Northwind database.

    I use the textbox to capture the user values for Order header. As for detail, I use DetailView for insert and update record, and gridview is use to display order details.

    An a submit button to save all records to the server.

    As we all know the Add and update features In detailview will update the database once user click insert or update. It is a good features but the header is not save yet.

    How should I handle this?

    Please advice.

  • could you tell me, why
    project>add new item>dataset are different in windows forms and web site projects, but have the same extension? is it possible to use in web site windows form's xsd dataset and vice versa? where to find more info?

  • Hi Gierdrius,

    The .XSD files can be used both in Web Application Projects and WinForms project interchangably.

    The .XSD files are slightly different between web site projects and winforms projects, though, and need to be updated in order to be shared.

    Thanks,

    Scott

  • it is fine.
    i want some more advanced material

Comments have been disabled for this content.