Solved

Building a common library for .Net Applications

Posted on 2014-03-17
3
262 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 20

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
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, f…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

911 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

23 Experts available now in Live!

Get 1:1 Help Now