Solved

Building a common library for .Net Applications

Posted on 2014-03-17
3
259 Views
Last Modified: 2014-03-24
Hi guys,

I am jumping into the world of OOP. For start can you please advise me in building a library  which contains classes like connection string  and open close, Classes which return update, insert and delete query, classes which return list<t> or data sets. I am looking to build this library generic to use with different applications.

kindest regards,
0
Comment
Question by:shah36
3 Comments
 
LVL 1

Expert Comment

by:Lucky Ncube
ID: 39934034
Here is an example of how I do it using Classes.
1. Define class called tblCIty to present my database table called tblCIty. Please note that this is an instantiating class
Public Class tblCity

    Property CityID As Guid
    Property City As String

    Sub New()

    End Sub
    Sub New(ByVal sqlRdr As SqlDataReader)
        _CityID = sqlRdr("CityID")
        _City = sqlRdr("City")
    End Sub
    Public Overrides Function ToString() As String
        Return _City
    End Function

End Class

Open in new window


After I have by class I can use the class to now list the Cities by add them to the List as Shown Below:
Public Shared Function List(ByVal sqlConn As SqlConnection, Optional ByVal sqlTrans As SqlTransaction = Nothing) As List(Of tblCity)
        Dim iList As New List(Of tblCity)
        Using sqlCmd As New SqlCommand("City_List", sqlConn, sqlTrans)
            sqlCmd.CommandType = CommandType.StoredProcedure
            Using sqlRdr As SqlDataReader = sqlCmd.ExecuteReader
                While sqlRdr.Read
                    iList.Add(New tblCity(sqlRdr))
                End While
                sqlRdr.Close()
            End Using
        End Using
        Return iList
    End Function

Open in new window

This  simple object manipulating code.
0
 
LVL 19

Accepted Solution

by:
Daniel Van Der Werken earned 500 total points
ID: 39934407
This kind of thing has been done a lot. Your question doesn't have any easy or simple one-page answer. First, I would direct you to libraries that already exist that provide for this functionality in the .NET framework. Mainly, the Entity Framework:
http://msdn.microsoft.com/en-us/data/ef.aspx

Otherwise, a simple web search on ".net c# crud framework" will give you a bunch of options to choose from.
0
 

Author Closing Comment

by:shah36
ID: 39950535
Thanks gave me the start
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Image(7) 1 37
getting id from database 5 24
What .NET website keeps me current? 9 32
bulid json format 3 21
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

762 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now