none
Data Access Layer - guidance RRS feed

  • Question

  • Hi,

    I'm a newbie building my first database app in vb.net (SQL CE 3.5) using dataset Designer.

    I'm wanting to design my application in the right way and so want to have separate Data, Bussiness, Presentation layers.

    Has anyone got any good links to how to design a 'simple' data access layer? I think I'm going to have to make a DataAccess class that will have methods for interacting with the physical database. It isn't easy to find a well-written, clear explanation of how to do it though !

    Thanks for any assistance ! ... 
    Wednesday, January 13, 2010 9:57 AM

Answers

  • Hi..

    Microsoft has provided a Various Application Blocks for doing common activities in .NET.

    Download the Microsoft Enterprise Library in NET. In that you can find the Data Access Application Block.

    Which will helpful for creating the Data Access Layers.

    To download the follow the link : http://www.microsoft.com/downloads/details.aspx?FamilyId=1643758B-2986-47F7-B529-3E41584B6CE5&displaylang=en

    Thanks in Advance


    Best Regards,
    Gopi V

    If you have found this post helpful, please click the Vote as Helpful link (the green triangle and number on the top-left).

    If this post answers your question, click the Mark As Answered link below. It helps others who experience the same issue in future to find the solution.

    Wednesday, January 13, 2010 10:40 AM
  • SQL database is the data provider for your application. Like ado.net supports many providers, OLEDB, sqlClient, Oracle,ODBC etc. In your case, you can use SqlClient class, which interally talks to database engine. This class will help you to do all database specfic operations .For eg. opening a new connection, closing connection, executing a query/procedure etc.

    You need a Adapter object to execute these operations. in which you can set your DB proerties like, connection strings, db credentials etc.

    once you are able to connect to the db, you can use DataSet, DataTable, DataRow, DataColumn classes to operate the data .

    For any query operations (get/set data from db), you need a Command (class) object. Once you set command object properties, call Command.ExecuteNonQuery( this is for queries which doesn't return any value. eg. and instert query)

    let me know, if you need more details
    Thanks Mike --------Please mark as answer if it is useful----------
    Friday, January 15, 2010 4:37 AM

All replies

  • Hi..

    Microsoft has provided a Various Application Blocks for doing common activities in .NET.

    Download the Microsoft Enterprise Library in NET. In that you can find the Data Access Application Block.

    Which will helpful for creating the Data Access Layers.

    To download the follow the link : http://www.microsoft.com/downloads/details.aspx?FamilyId=1643758B-2986-47F7-B529-3E41584B6CE5&displaylang=en

    Thanks in Advance


    Best Regards,
    Gopi V

    If you have found this post helpful, please click the Vote as Helpful link (the green triangle and number on the top-left).

    If this post answers your question, click the Mark As Answered link below. It helps others who experience the same issue in future to find the solution.

    Wednesday, January 13, 2010 10:40 AM
  • Hi, thanks for that.  I've downloaded and looked at some source .... but must admit, this is WAY over my head and far too complex for my little PC-based application. I'm just looking at the basics. For instance I 'think' I'm doing the right thing by making a DataAccess class and then setting properties and methods to interact with my TableAdapter queries. This way I'm providing my Business layer with only abstract methods and means the Business layer doesn't need to 'know' what an SQL database is - which I believe is the whole point of layers. 

    I'm really looking for some article or guidance that is way simpler than these Microsoft standard blocks - so I can learn the fundamentals and go from there.

    Appreciate your help though ! 
    Wednesday, January 13, 2010 12:00 PM
  • SQL database is the data provider for your application. Like ado.net supports many providers, OLEDB, sqlClient, Oracle,ODBC etc. In your case, you can use SqlClient class, which interally talks to database engine. This class will help you to do all database specfic operations .For eg. opening a new connection, closing connection, executing a query/procedure etc.

    You need a Adapter object to execute these operations. in which you can set your DB proerties like, connection strings, db credentials etc.

    once you are able to connect to the db, you can use DataSet, DataTable, DataRow, DataColumn classes to operate the data .

    For any query operations (get/set data from db), you need a Command (class) object. Once you set command object properties, call Command.ExecuteNonQuery( this is for queries which doesn't return any value. eg. and instert query)

    let me know, if you need more details
    Thanks Mike --------Please mark as answer if it is useful----------
    Friday, January 15, 2010 4:37 AM
  • Sorry, forgot to thank you for this, Mike!
    Friday, February 19, 2010 8:43 AM
  • Zippy, check out my 3-part series on Data Access for some ideas:

    http://geek-goddess-bonnie.blogspot.com/2009/09/dataaccess-part-i.html
    http://geek-goddess-bonnie.blogspot.com/2009/10/dataaccess-part-ii.html
    http://geek-goddess-bonnie.blogspot.com/2009/10/dataaccess-part-iii.html

    Each post adds extra complexity but more flexiblity. However, even just the information in the first post is enough to get you going and is a great starting point for those wishing to have more control over their data access.


    ~~Bonnie Berent [C# MVP]

    geek-goddess-bonnie.blogspot.com
    Wednesday, February 24, 2010 5:29 AM
  • Hey Bonnie, that is really useful thanks. Your comments about TableAdapters and Wizards also look interesting - I've dabbled in the past and got loads of auto-generated software that got in a complete tangle when I changed things.

    Anyway I'll have a good read.

    As an aside ... Pity your examples are in C# and not VB though ! This might make some people laugh, but as a newbie to .NET I must admit I am wondering 'why' C# exists at all, as VB looks so much cleaner to me in code and 'probably' has the same functionality?? Cue more replies making me look a dummy :o)

    Wednesday, February 24, 2010 8:08 AM
  • Hey Zippy, I feel just the opposite re C# vs VB ... I thnk C# looks much cleaner and is easier to read. But you know, that's probably why they have different .NET languages ... so people can choose which one they feel more comfortable with. The end result is the same once it's all compiled.

    Take a look at this link to translate between C# and VB and vice versa: http://www.carlosag.net/Tools/CodeTranslator/


    ~~Bonnie Berent [C# MVP]

    geek-goddess-bonnie.blogspot.com
    Wednesday, February 24, 2010 2:42 PM
  • Glad I could help you, Ella! =0)
    ~~Bonnie Berent [C# MVP]

    geek-goddess-bonnie.blogspot.com
    Thursday, October 21, 2010 4:35 AM